fix: Use a channel for bufferring tailnet connection updates (#3940)

This commit is contained in:
Kyle Carberry 2022-09-07 22:18:35 -05:00 committed by GitHub
parent 519d724ca4
commit 7718fa53c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 13 deletions

2
go.mod
View File

@ -49,7 +49,7 @@ replace github.com/tcnksm/go-httpstat => github.com/kylecarbs/go-httpstat v0.0.0
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20220907140144-9abacd14802f
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20220907193453-fb5ba5ab658d
require (
cdr.dev/slog v1.4.2-0.20220525200111-18dce5c2cd5f

4
go.sum
View File

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

View File

@ -260,29 +260,38 @@ func (c *Conn) SetNodeCallback(callback func(node *Node)) {
DERPLatency: c.lastDERPLatency,
}
}
// A send queue must be used so nodes are sent in order.
queue := make(chan *Node, 16)
go func() {
for {
select {
case <-c.closed:
return
case node := <-queue:
callback(node)
}
}
}()
c.wireguardEngine.SetNetInfoCallback(func(ni *tailcfg.NetInfo) {
c.lastMutex.Lock()
c.lastPreferredDERP = ni.PreferredDERP
c.lastDERPLatency = ni.DERPLatency
node := makeNode()
queue <- node
c.lastMutex.Unlock()
callback(node)
})
c.wireguardEngine.SetStatusCallback(func(s *wgengine.Status, err error) {
if err != nil {
return
}
endpoints := make([]string, 0, len(s.LocalAddrs))
c.lastMutex.Lock()
c.lastEndpoints = make([]string, 0, len(s.LocalAddrs))
for _, addr := range s.LocalAddrs {
endpoints = append(endpoints, addr.Addr.String())
c.lastEndpoints = append(c.lastEndpoints, addr.Addr.String())
}
go func() {
c.lastMutex.Lock()
c.lastEndpoints = endpoints
node := makeNode()
c.lastMutex.Unlock()
callback(node)
}()
node := makeNode()
queue <- node
c.lastMutex.Unlock()
})
}