ensure relay context and subscriptions are closed when we lose connectivity.

This commit is contained in:
fiatjaf
2023-05-30 17:44:25 -03:00
parent 19d96e3566
commit 9cafea7e2a
3 changed files with 15 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"sync"
"time"
"github.com/puzpuzpuz/xsync"
)
@@ -40,7 +41,9 @@ func (pool *SimplePool) EnsureRelay(url string) (*Relay, error) {
} else {
var err error
// we use this ctx here so when the pool dies everything dies
relay, err = RelayConnect(pool.Context, nm)
ctx, cancel := context.WithTimeout(pool.Context, time.Second*15)
defer cancel()
relay, err = RelayConnect(ctx, nm)
if err != nil {
return nil, fmt.Errorf("failed to connect: %w", err)
}