Skip to content

Commit 85549c0

Browse files
committed
Fix race condition on connection to tsserver
1 parent 684abce commit 85549c0

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

cmd/wush/receive.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ func receiveCmd() *serpent.Command {
7171
if err != nil {
7272
return err
7373
}
74-
ts.Logf = func(string, ...any) {}
75-
ts.UserLogf = func(string, ...any) {}
7674

7775
ts.Up(ctx)
7876
fs := afero.NewOsFs()
@@ -111,7 +109,13 @@ func newTSNet(direction string) (*tsnet.Server, error) {
111109
srv.AuthKey = direction
112110
srv.ControlURL = "http://localhost:8080"
113111
srv.Logf = func(format string, args ...any) {}
112+
// srv.Logf = func(format string, args ...any) {
113+
// fmt.Printf(format+"\n", args...)
114+
// }
114115
srv.UserLogf = func(format string, args ...any) {}
116+
// srv.UserLogf = func(format string, args ...any) {
117+
// fmt.Printf(format+"\n", args...)
118+
// }
115119

116120
srv.Store, err = store.New(func(format string, args ...any) {}, "mem:wush")
117121
if err != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ require (
3030
golang.org/x/sys v0.24.0
3131
golang.org/x/term v0.22.0
3232
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9
33-
gvisor.dev/gvisor v0.0.0-20240722211153-64c016c92987
3433
tailscale.com v1.70.0
3534
)
3635

@@ -216,6 +215,7 @@ require (
216215
google.golang.org/protobuf v1.34.2 // indirect
217216
gopkg.in/DataDog/dd-trace-go.v1 v1.64.0 // indirect
218217
gopkg.in/yaml.v3 v3.0.1 // indirect
218+
gvisor.dev/gvisor v0.0.0-20240722211153-64c016c92987 // indirect
219219
nhooyr.io/websocket v1.8.10 // indirect
220220
storj.io/drpc v0.0.33 // indirect
221221
)

tsserver/server.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (s *server) ListenAndServe(_ context.Context) error {
123123
}
124124
}()
125125

126-
return http.Serve(s.ll, r)
126+
return http.Serve(s.ml, r)
127127
}
128128

129129
type memListen struct {
@@ -153,10 +153,10 @@ func (m *memListen) Addr() net.Addr {
153153
return &net.IPAddr{}
154154
}
155155

156-
func (m *memListen) Dial() net.Conn {
156+
func (m *memListen) Dial() (net.Conn, error) {
157157
in, out := net.Pipe()
158158
m.listen <- in
159-
return out
159+
return out, nil
160160
}
161161

162162
type memDialer struct {
@@ -170,7 +170,7 @@ func (m memDialer) Dial(network string, address string) (net.Conn, error) {
170170
return nil, errors.New("tls not supported")
171171
}
172172

173-
return m.ll.Dial()
173+
return m.ml.Dial()
174174
}
175175

176176
func (m memDialer) DialContext(ctx context.Context, network string, address string) (net.Conn, error) {
@@ -183,7 +183,7 @@ func (m memDialer) DialContext(ctx context.Context, network string, address stri
183183
return d.DialContext(ctx, network, address)
184184
}
185185

186-
return m.ll.Dial()
186+
return m.ml.Dial()
187187
}
188188

189189
func (s *server) Dialer() netns.Dialer {
@@ -253,7 +253,13 @@ func (s *server) NoiseUpgradeHandler(w http.ResponseWriter, r *http.Request) {
253253
w,
254254
r,
255255
s.noisePrivateKey,
256-
ns.earlyNoise,
256+
// ns.earlyNoise,
257+
// TODO: for some reason when using an unbuffered network connection
258+
// (such as our in-memory connection to the tsserver), the client will
259+
// just hang on https://github.com/coadler/tailscale/blob/main/internal/noiseconn/conn.go#L59
260+
// and https://github.com/coadler/tailscale/blob/main/control/controlhttp/server.go#L107.
261+
// Disabling the early write seems to fix it.
262+
nil,
257263
)
258264
if err != nil {
259265
// http.Error(w, err.Error(), http.StatusInternalServerError)

0 commit comments

Comments
 (0)