fix(gemini): bound cancel goroutine to Download lifetime

This commit is contained in:
2026-06-30 19:24:45 +02:00
parent 49012fbf82
commit c1373f0d61
+10 -2
View File
@@ -100,10 +100,18 @@ func (p *Protocol) downloadWithRedirects(ctx context.Context, req *core.Download
// 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. // 30-second deadline. The done channel bounds the goroutine to
// the lifetime of this call: when Download returns, defer
// close(done) lets the goroutine exit even if the parent context
// was never cancelled.
done := make(chan struct{})
defer close(done)
go func() { go func() {
<-ctx.Done() select {
case <-ctx.Done():
conn.Close() conn.Close()
case <-done:
}
}() }()
// Send request: URL + CRLF // Send request: URL + CRLF