From e553a46a405da7735c680e6f450207f28cd3f8c6 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 2 Jul 2025 15:04:40 +1000 Subject: [PATCH] Fix leaked goroutines when webseed requests are cancelled --- webseed/client.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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) -- 2.51.0