Skip to content

Commit f46aaee

Browse files
committed
fix: find non stun nodes for websocket fallback
If the first node was a STUN node, it would naturally fail to dial. A user found this and reported it!
1 parent d9efcc0 commit f46aaee

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

derp/derphttp/derphttp_client.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,26 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
347347
case c.useWebsockets():
348348
var urlStr string
349349
var tlsConfig *tls.Config
350+
// WebSocket connections require a DERP to proxy.
351+
// DERP mappings have no explicit requirements on the ordering
352+
// of DERP vs STUNOnly nodes. So we pick the first non-STUNOnly one.
353+
var node *tailcfg.DERPNode
354+
for _, n := range reg.Nodes {
355+
if n.STUNOnly {
356+
continue
357+
}
358+
node = n
359+
break
360+
}
361+
if node == nil {
362+
return nil, 0, errors.New("no non-STUN-only nodes in region")
363+
}
350364
if c.url != nil {
351365
urlStr = c.url.String()
352366
tlsConfig = c.tlsConfig(nil)
353367
} else {
354-
urlStr = c.urlString(reg.Nodes[0])
355-
tlsConfig = c.tlsConfig(reg.Nodes[0])
368+
urlStr = c.urlString(node)
369+
tlsConfig = c.tlsConfig(node)
356370
}
357371
c.logf("%s: connecting websocket to %v", caller, urlStr)
358372
conn, err := dialWebsocketFunc(ctx, urlStr, tlsConfig, c.Header)

0 commit comments

Comments
 (0)