From: Matt Joiner Date: Wed, 2 Jul 2025 05:04:40 +0000 (+1000) Subject: Fix leaked goroutines when webseed requests are cancelled X-Git-Tag: v1.59.0~54 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e553a46a405da7735c680e6f450207f28cd3f8c6;p=btrtrc.git Fix leaked goroutines when webseed requests are cancelled --- diff --git a/webseed/client.go b/webseed/client.go index edf1ef6e..ac58ec54 100644 --- a/webseed/client.go +++ b/webseed/client.go @@ -39,13 +39,15 @@ type requestPart struct { type Request struct { cancel func() - // Closed in the machinery when cancelled? - Body io.Reader - err chan error + Body io.Reader + // Closed with error to unstick copy routine when context isn't checked. + bodyPipe *io.PipeReader + err chan error } func (r Request) Cancel() { r.cancel() + r.bodyPipe.CloseWithError(context.Canceled) } type Client struct { @@ -127,8 +129,9 @@ func (ws *Client) StartNewRequest(r RequestSpec) Request { } body, w := io.Pipe() req := Request{ - cancel: cancel, - Body: body, + cancel: cancel, + Body: body, + bodyPipe: body, } go func() { err := ws.readRequestPartResponses(ctx, w, requestParts)