From 38a6ca92b9546fb92fdaa3c82a182681a09a5f14 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 4 Nov 2025 08:26:08 -0300 Subject: [PATCH] b0: remove hardcoded timeouts in blossom client. see nostr:nevent1qvzqqqqqqypzqmjxss3dld622uu8q25gywum9qtg4w4cv4064jmg20xsac2aam5nqyd8wumn8ghj7urewfsk66ty9enxjct5dfskvtnrdakj7qpqrfcfcq52gfv6znm8hkdpa3rlxad72zl6ah4haaneqzdxwmnamg3sk2sztg --- nipb0/blossom/client.go | 13 +++++-------- nipb0/blossom/http.go | 8 +++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/nipb0/blossom/client.go b/nipb0/blossom/client.go index 201945d..fc878d3 100644 --- a/nipb0/blossom/client.go +++ b/nipb0/blossom/client.go @@ -30,16 +30,13 @@ func NewClient(mediaserver string, signer nostr.Signer) *Client { // createHTTPClient creates a properly configured HTTP client func createHTTPClient() *fasthttp.Client { - readTimeout, _ := time.ParseDuration("10s") - writeTimeout, _ := time.ParseDuration("10s") - maxIdleConnDuration, _ := time.ParseDuration("1h") return &fasthttp.Client{ - ReadTimeout: readTimeout, - WriteTimeout: writeTimeout, - MaxIdleConnDuration: maxIdleConnDuration, - NoDefaultUserAgentHeader: true, // Don't send: User-Agent: fasthttp - DisableHeaderNamesNormalizing: true, // If you set the case on your headers correctly you can enable this + MaxIdleConnDuration: time.Hour, + DisableHeaderNamesNormalizing: true, // because our headers are properly constructed DisablePathNormalizing: true, + + Name: "nl-b", // user-agent + // increase DNS cache time to an hour instead of default minute Dial: (&fasthttp.TCPDialer{ Concurrency: 4096, diff --git a/nipb0/blossom/http.go b/nipb0/blossom/http.go index c31e5ee..0551aeb 100644 --- a/nipb0/blossom/http.go +++ b/nipb0/blossom/http.go @@ -46,7 +46,13 @@ func (c *Client) httpCall( req.SetBodyStream(body, int(contentSize)) } - err := c.httpClient.Do(req, resp) + var err error + if deadline, ok := ctx.Deadline(); ok { + err = c.httpClient.DoDeadline(req, resp, deadline) + } else { + err = c.httpClient.Do(req, resp) + } + if err != nil { return fmt.Errorf("failed to call %s: %w\n", url, err) }