Skip to content

Commit 7718fa5

Browse files
authored
fix: Use a channel for bufferring tailnet connection updates (#3940)
1 parent 519d724 commit 7718fa5

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ replace github.com/tcnksm/go-httpstat => github.com/kylecarbs/go-httpstat v0.0.0
4949

5050
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
5151
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
52-
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20220907140144-9abacd14802f
52+
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20220907193453-fb5ba5ab658d
5353

5454
require (
5555
cdr.dev/slog v1.4.2-0.20220525200111-18dce5c2cd5f

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1 h1:UqBrPWSYvRI2s5RtOu
352352
github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
353353
github.com/coder/retry v1.3.0 h1:5lAAwt/2Cm6lVmnfBY7sOMXcBOwcwJhmV5QGSELIVWY=
354354
github.com/coder/retry v1.3.0/go.mod h1:tXuRgZgWjUnU5LZPT4lJh4ew2elUhexhlnXzrJWdyFY=
355-
github.com/coder/tailscale v1.1.1-0.20220907140144-9abacd14802f h1:iWOlTwTwh1hCr6I0D2bWFHKRaPb7PmcxPISFkkj3DdM=
356-
github.com/coder/tailscale v1.1.1-0.20220907140144-9abacd14802f/go.mod h1:MO+tWkQp2YIF3KBnnej/mQvgYccRS5Xk/IrEpZ4Z3BU=
355+
github.com/coder/tailscale v1.1.1-0.20220907193453-fb5ba5ab658d h1:IQ8wJn8MfDS+sesYPpn3EDAyvoGMxFvyyE9uWtcfU6w=
356+
github.com/coder/tailscale v1.1.1-0.20220907193453-fb5ba5ab658d/go.mod h1:MO+tWkQp2YIF3KBnnej/mQvgYccRS5Xk/IrEpZ4Z3BU=
357357
github.com/coder/wireguard-go/tun/netstack v0.0.0-20220823170024-a78136eb0cab h1:9yEvRWXXfyKzXu8AqywCi+tFZAoqCy4wVcsXwuvZNMc=
358358
github.com/coder/wireguard-go/tun/netstack v0.0.0-20220823170024-a78136eb0cab/go.mod h1:TCJ66NtXh3urJotTdoYQOHHkyE899vOQl5TuF+WLSes=
359359
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=

tailnet/conn.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -260,29 +260,38 @@ func (c *Conn) SetNodeCallback(callback func(node *Node)) {
260260
DERPLatency: c.lastDERPLatency,
261261
}
262262
}
263+
// A send queue must be used so nodes are sent in order.
264+
queue := make(chan *Node, 16)
265+
go func() {
266+
for {
267+
select {
268+
case <-c.closed:
269+
return
270+
case node := <-queue:
271+
callback(node)
272+
}
273+
}
274+
}()
263275
c.wireguardEngine.SetNetInfoCallback(func(ni *tailcfg.NetInfo) {
264276
c.lastMutex.Lock()
265277
c.lastPreferredDERP = ni.PreferredDERP
266278
c.lastDERPLatency = ni.DERPLatency
267279
node := makeNode()
280+
queue <- node
268281
c.lastMutex.Unlock()
269-
callback(node)
270282
})
271283
c.wireguardEngine.SetStatusCallback(func(s *wgengine.Status, err error) {
272284
if err != nil {
273285
return
274286
}
275-
endpoints := make([]string, 0, len(s.LocalAddrs))
287+
c.lastMutex.Lock()
288+
c.lastEndpoints = make([]string, 0, len(s.LocalAddrs))
276289
for _, addr := range s.LocalAddrs {
277-
endpoints = append(endpoints, addr.Addr.String())
290+
c.lastEndpoints = append(c.lastEndpoints, addr.Addr.String())
278291
}
279-
go func() {
280-
c.lastMutex.Lock()
281-
c.lastEndpoints = endpoints
282-
node := makeNode()
283-
c.lastMutex.Unlock()
284-
callback(node)
285-
}()
292+
node := makeNode()
293+
queue <- node
294+
c.lastMutex.Unlock()
286295
})
287296
}
288297

0 commit comments

Comments
 (0)