Skip to content

Commit a2f48f0

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 a2f48f0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

derp/derphttp/derphttp_client.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,23 @@ 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+
var node *tailcfg.DERPNode
351+
for _, n := range reg.Nodes {
352+
if n.STUNOnly {
353+
continue
354+
}
355+
node = n
356+
break
357+
}
358+
if node == nil {
359+
return nil, 0, errors.New("no non-STUN-only nodes in region")
360+
}
350361
if c.url != nil {
351362
urlStr = c.url.String()
352363
tlsConfig = c.tlsConfig(nil)
353364
} else {
354-
urlStr = c.urlString(reg.Nodes[0])
355-
tlsConfig = c.tlsConfig(reg.Nodes[0])
365+
urlStr = c.urlString(node)
366+
tlsConfig = c.tlsConfig(node)
356367
}
357368
c.logf("%s: connecting websocket to %v", caller, urlStr)
358369
conn, err := dialWebsocketFunc(ctx, urlStr, tlsConfig, c.Header)

0 commit comments

Comments
 (0)