fix(gopher): preserve partial state when EOF follows context cancellation
This commit is contained in:
@@ -231,6 +231,15 @@ func (p *Protocol) downloadText(ctx context.Context, reader *bufio.Reader, req *
|
|||||||
line, err := reader.ReadString('\n')
|
line, err := reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
// The connection may have been closed by our context
|
||||||
|
// cancellation goroutine (or by the server after the
|
||||||
|
// client cancelled). If so, the EOF is not a genuine
|
||||||
|
// end-of-data but a side-effect of the cancel and we
|
||||||
|
// must persist the partial state before bailing.
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
saveGopherResume(req, bytesWritten)
|
||||||
|
return nil, ctx.Err()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
saveGopherResume(req, bytesWritten)
|
saveGopherResume(req, bytesWritten)
|
||||||
|
|||||||
Reference in New Issue
Block a user