mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
force a deadline of 7 seconds when connecting to relays (if not set).
must add documentation to these calls.
This commit is contained in:
parent
3349b2a52b
commit
0397395261
7
relay.go
7
relay.go
@ -65,6 +65,13 @@ func (r *Relay) Connect(ctx context.Context) error {
|
||||
return fmt.Errorf("invalid relay URL '%s'", r.URL)
|
||||
}
|
||||
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
// if no timeout is set, force it to 7 seconds
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithTimeout(ctx, 7*time.Second)
|
||||
defer cancel()
|
||||
}
|
||||
|
||||
socket, _, err := websocket.DefaultDialer.DialContext(ctx, r.URL, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error opening websocket to '%s': %w", r.URL, err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user