mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
fix pinging relays: use the main relay context, not the relay connection temporary context.
This commit is contained in:
parent
06a15fdaab
commit
3e1c0ddc7e
@ -3,9 +3,11 @@ package nostr
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
ws "github.com/coder/websocket"
|
||||
)
|
||||
@ -51,5 +53,7 @@ func (c *Connection) Close() error {
|
||||
}
|
||||
|
||||
func (c *Connection) Ping(ctx context.Context) error {
|
||||
ctx, cancel := context.WithTimeoutCause(ctx, time.Millisecond*800, errors.New("ping took too long"))
|
||||
defer cancel()
|
||||
return c.conn.Ping(ctx)
|
||||
}
|
||||
|
3
relay.go
3
relay.go
@ -186,7 +186,7 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if r.Connection != nil {
|
||||
err := r.Connection.Ping(ctx)
|
||||
err := r.Connection.Ping(r.connectionContext)
|
||||
if err != nil {
|
||||
InfoLogger.Printf("{%s} error writing ping: %v; closing websocket", r.URL, err)
|
||||
r.Close() // this should trigger a context cancelation
|
||||
@ -213,6 +213,7 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
|
||||
|
||||
for {
|
||||
buf.Reset()
|
||||
|
||||
if err := conn.ReadMessage(r.connectionContext, buf); err != nil {
|
||||
r.ConnectionError = err
|
||||
r.close(err)
|
||||
|
@ -55,12 +55,10 @@ func TestFollowListRecursion(t *testing.T) {
|
||||
results := make(chan result)
|
||||
go func() {
|
||||
for _, item := range followList.Items {
|
||||
go func() {
|
||||
fl := sys.FetchFollowList(ctx, item.Pubkey)
|
||||
meta := sys.FetchProfileMetadata(ctx, item.Pubkey)
|
||||
fmt.Println(" ~", item.Pubkey, meta.Name, len(fl.Items))
|
||||
results <- result{item.Pubkey, fl, meta}
|
||||
}()
|
||||
fl := sys.FetchFollowList(ctx, item.Pubkey)
|
||||
meta := sys.FetchProfileMetadata(ctx, item.Pubkey)
|
||||
fmt.Println(" ~", item.Pubkey, meta.Name, len(fl.Items))
|
||||
results <- result{item.Pubkey, fl, meta}
|
||||
}
|
||||
}()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user