-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Downloader: http panic connCount underflow #9964
Labels
bug
Something isn't working
Comments
AskAlexSharov
changed the title
http panic after
Downloader: http panic connCount underflow
Apr 17, 2024
I think that the underlying issue is in: https://github.com/anacrolix/torrent/blob/master/webseed/client.go func readRequestPartResponses(ctx context.Context, parts []requestPart) (_ []byte, err error) {
var buf bytes.Buffer
for _, part := range parts {
part.start() <--This calls http.Client Do in a seperate go routine
err = recvPartResult(ctx, &buf, part) <--This waits on a channel in this go routine and calls resp.Body.Close()
if err != nil {
err = fmt.Errorf("reading %q at %q: %w", part.req.URL, part.req.Header.Get("Range"), err)
break
}
}
return buf.Bytes(), err
} The code is here: part.start = func() {
go func() {
resp, err := ws.HttpClient.Do(req)
part.result <- requestPartResult{
resp: resp,
err: err,
}
}()
} and here: func recvPartResult(ctx context.Context, buf io.Writer, part requestPart) error {
result := <-part.result
// Make sure there's no further results coming, it should be a one-shot channel.
close(part.result)
if result.err != nil {
return result.err
}
defer result.resp.Body.Close()
var body io.Reader = result.resp.Body I dont think the inner go routine is required as the calls are already asynchronous so start can be just: func() (resp *http.Response, err error) {
return ws.HttpClient.Do(req)
}() I think it will remove the potential race condition |
fixed by anacrolix/torrent#933 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(I thought that after #9962 easier to reproduce next panics, but seems not).
and
maybe it's because of some resp.Body not closed
maybe it's because another panic happened (but we don't see it) - maybe inside new RoundTrip func
The text was updated successfully, but these errors were encountered: