fix main relay context being canceled instead of just the dial context.

This commit is contained in:
fiatjaf
2025-07-11 13:01:04 -03:00
parent dcd505712a
commit 9f8b810882
3 changed files with 12 additions and 18 deletions

View File

@@ -34,7 +34,13 @@ func NewConnection(
requestHeader http.Header,
tlsConfig *tls.Config,
) (*Connection, error) {
c, _, err := ws.Dial(ctx, url, getConnectionOptions(requestHeader, tlsConfig))
dialCtx := ctx
if _, ok := dialCtx.Deadline(); !ok {
// if no timeout is set, force it to 7 seconds
dialCtx, _ = context.WithTimeoutCause(ctx, 7*time.Second, errors.New("connection took too long"))
}
c, _, err := ws.Dial(dialCtx, url, getConnectionOptions(requestHeader, tlsConfig))
if err != nil {
return nil, err
}