close relay websockets cleanly.

This commit is contained in:
fiatjaf 2024-01-11 21:29:39 -03:00
parent 637b9440ef
commit a30f422d7d
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
3 changed files with 21 additions and 1 deletions

View File

@ -108,6 +108,12 @@ example:
} }
} }
defer func() {
for _, relay := range relays {
relay.Close()
}
}()
// gather the secret key // gather the secret key
sec, err := gatherSecretKeyFromArguments(c) sec, err := gatherSecretKeyFromArguments(c)
if err != nil { if err != nil {

View File

@ -24,6 +24,15 @@ var fetch = &cli.Command{
}, },
ArgsUsage: "[nip19code]", ArgsUsage: "[nip19code]",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
pool := nostr.NewSimplePool(c.Context)
defer func() {
pool.Relays.Range(func(_ string, relay *nostr.Relay) bool {
relay.Close()
return true
})
}()
for code := range getStdinLinesOrFirstArgument(c) { for code := range getStdinLinesOrFirstArgument(c) {
filter := nostr.Filter{} filter := nostr.Filter{}
@ -67,7 +76,6 @@ var fetch = &cli.Command{
authorHint = v authorHint = v
} }
pool := nostr.NewSimplePool(c.Context)
if authorHint != "" { if authorHint != "" {
relayList := sdk.FetchRelaysForPubkey(c.Context, pool, authorHint, relayList := sdk.FetchRelaysForPubkey(c.Context, pool, authorHint,
"wss://purplepag.es", "wss://relay.damus.io", "wss://relay.noswhere.com", "wss://purplepag.es", "wss://relay.damus.io", "wss://relay.noswhere.com",

6
req.go
View File

@ -135,6 +135,12 @@ example:
for i, relay := range relays { for i, relay := range relays {
relayUrls[i] = relay.URL relayUrls[i] = relay.URL
} }
defer func() {
for _, relay := range relays {
relay.Close()
}
}()
} }
for stdinFilter := range getStdinLinesOrBlank() { for stdinFilter := range getStdinLinesOrBlank() {