-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Description
We probably found a bug in algoliasearch-client-go v4 impacting the retry strategy.
Issue :
After an http error on the first try (502. for example) , the next attempts to reach fallback host are failing with this error . http.nothingWrittenError{error:(*errors.errorString)(0xc000628ad0)
These retry requests are never received by cluster.
Probable cause :
After a request using http.Client.Do(req), the request body (req.Body) is consumed (i.e., read once and discarded). If you try to reuse the same http.Request for a retry or a redirect, you’ll run into one of the following issues:
- The body is nil on retry.
- You get errors like: http: ContentLength != 0 with nil Body.
- The request is sent with an empty body.
Language
Go
Client
Search
Steps to reproduce
Not easy to reproduce.
- Perform a request with algoliasearch-go v4.22 .
- The response to the first request to https://APPID-dsn.algolia.net/1/indexes needs be an http error triggering a retry on the fallback hosts (http/502)
- Constatation : The retry strategy won't work whereas the other nodes are available
Relevant log output
On the cluster we only see request to APPID-dsn.algolia.net and not APPID-X.algolianet.com which are the default retry strategy hosts.
22/Jul/2025:14:50:10 +0000 ctir4uhxjg-dsn.algolia.net 502 POST 150 "-" "Algolia for Go (4.22.0); Go (go1.24.4); Search (4.22.0)" 0.008 -, -, - -, -, - 0.006, 0.001, 0.002
22/Jul/2025:14:50:10 +0000 ctir4uhxjg-dsn.algolia.net 502 POST 150 "-" "Algolia for Go (4.22.0); Go (go1.24.4); Search (4.22.0)" 0.029 -, -, - -, -, - 0.017, 0.001, 0.011
22/Jul/2025:14:50:10 +0000 ctir4uhxjg-dsn.algolia.net 502 POST 150 "-" "Algolia for Go (4.22.0); Go (go1.24.4); Search (4.22.0)" 0.040 -, -, - -, -, - 0.036, 0.003, 0.001
22/Jul/2025:14:50:10 +0000 ctir4uhxjg-dsn.algolia.net 502 POST 150 "-" "Algolia for Go (4.22.0); Go (go1.24.4); Search (4.22.0)" 0.004 -, -, - -, -, - 0.002, 0.001, 0.001
22/Jul/2025:14:50:10 +0000 ctir4uhxjg-dsn.algolia.net 502 POST 150 "-" "Algolia for Go (4.22.0); Go (go1.24.4); Search (4.22.0)" 0.025 -, -, - -, -, - 0.002, 0.011, 0.012
22/Jul/2025:14:50:10 +0000 ctir4uhxjg-dsn.algolia.net 502 POST 150 "-" "Algolia for Go (4.22.0); Go (go1.24.4); Search (4.22.0)" 0.021 -, -, - -, -, - 0.006, 0.010, 0.005
22/Jul/2025:14:50:10 +0000 ctir4uhxjg-dsn.algolia.net 502 POST 150 "-" "Algolia for Go (4.22.0); Go (go1.24.4); Search (4.22.0)" 0.054 -, -, - -, -, - 0.047, 0.001, 0.006
22/Jul/2025:14:50:10 +0000 ctir4uhxjg-dsn.algolia.net 502 POST 150 "-" "Algolia for Go (4.22.0); Go (go1.24.4); Search (4.22.0)" 0.054 -, -, - -, -, - 0.025, 0.015, 0.014
On the client side after adding debug :
> ALGOLIA DEBUG: do not know how to display &url.Error{Op:"Post", URL:"https://CTIR4UHXJG-1.algolianet.com/1/indexes/test_index/query?hitsPerPage=1", Err:http.nothingWrittenError{error:(*errors.errorString)(0xc0009a63e0)}}
took 8.277µs
cannot perform request:
error=Post "https://CTIR4UHXJG-1.algolianet.com/1/indexes/test_index/query?hitsPerPage=1": http: ContentLength=13 with Body length 0
method=POST
Search error: failed to do request: all hosts have been contacted unsuccessfully, it can either be a server or a network error or wrong appID/key credentials were used. cannot perform request:
error=502
method=POST
url=https://CTIR4UHXJG-dsn.algolia.net/1/indexes/test_index/query?hitsPerPage=1
body=&{%!s(*http.body=&{0xc000a5f4e8 <nil> <nil> false false {{} {0 0}} false false false <nil>}) {{} {%!s(int32=0) %!s(uint32=0)}} %!s(bool=false) <nil> %!s(func(error) error=0x63dce0) %!s(func() error=0x63ddc0)}
cannot perform request:
error=Post "https://CTIR4UHXJG-2.algolianet.com/1/indexes/test_index/query?hitsPerPage=1": http: ContentLength=13 with Body length 0
method=POST
url=https://CTIR4UHXJG-2.algolianet.com/1/indexes/test_index/query?hitsPerPage=1
cannot perform request:
error=Post "https://CTIR4UHXJG-1.algolianet.com/1/indexes/test_index/query?hitsPerPage=1": http: ContentLength=13 with Body length 0
method=POST
url=https://CTIR4UHXJG-1.algolianet.com/1/indexes/test_index/query?hitsPerPage=1
cannot perform request:
error=Post "https://CTIR4UHXJG-3.algolianet.com/1/indexes/test_index/query?hitsPerPage=1": http: ContentLength=13 with Body length 0
method=POST
url=https://CTIR4UHXJG-3.algolianet.com/1/indexes/test_index/query?hitsPerPage=1
Self-service
- I'd be willing to fix this bug myself