Skip to content

Commit f01c355

Browse files
committed
Be sure to cancel context when Close is called.
When I moved the context below the close calls to fix the issue with cancel interfering with file finalizing, I didn't take into account the returns. The context cancel needed to be done regardless which this does by moving it into a defer.
1 parent 0f45c1c commit f01c355

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

request.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ func (r *Request) getLister() ListerAt {
152152

153153
// Close reader/writer if possible
154154
func (r *Request) close() error {
155+
defer func() {
156+
if r.cancelCtx != nil {
157+
r.cancelCtx()
158+
}
159+
}()
155160
rd := r.getReader()
156161
if c, ok := rd.(io.Closer); ok {
157162
return c.Close()
@@ -160,9 +165,6 @@ func (r *Request) close() error {
160165
if c, ok := wt.(io.Closer); ok {
161166
return c.Close()
162167
}
163-
if r.cancelCtx != nil {
164-
r.cancelCtx()
165-
}
166168
return nil
167169
}
168170

0 commit comments

Comments
 (0)