fix(gopher): bound cancel goroutine to Download lifetime
This commit is contained in:
@@ -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
|
||||
// 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() {
|
||||
<-ctx.Done()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
conn.Close()
|
||||
case <-done:
|
||||
}
|
||||
}()
|
||||
|
||||
// Send selector + CRLF
|
||||
|
||||
Reference in New Issue
Block a user