fix(gopher): bound cancel goroutine to Download lifetime

This commit is contained in:
2026-06-30 14:01:11 +02:00
parent 3384e2b344
commit 88e210daaf
+10 -2
View File
@@ -83,10 +83,18 @@ func (p *Protocol) Download(ctx context.Context, req *core.DownloadRequest) (*co
// Close the connection when the context is cancelled so any // Close the connection when the context is cancelled so any
// blocking Read returns immediately instead of waiting for the // blocking Read returns immediately instead of waiting for the
// 30-second deadline. // dial deadline. The done channel bounds the goroutine to the
// lifetime of Download: the goroutine exits either when the
// context fires (we close the conn) or when Download returns
// successfully and defer close(done) signals shutdown.
done := make(chan struct{})
defer close(done)
go func() { go func() {
<-ctx.Done() select {
case <-ctx.Done():
conn.Close() conn.Close()
case <-done:
}
}() }()
// Send selector + CRLF // Send selector + CRLF