8000 request.close should close files before cancel · etherscan-io/sftp@43ec6c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 43ec6c6

Browse files
committed
request.close should close files before cancel
File reading/writeing might block on close until finished. If the context's cancel is run first it can cancel the session before that finishes. So the context's cancel should always be run last.
1 parent 09448a4 commit 43ec6c6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

request.go

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

153153
// Close reader/writer if possible
154154
func (r *Request) close() error {
155-
if r.cancelCtx != nil {
156-
r.cancelCtx()
157-
}
158155
rd := r.getReader()
159156
if c, ok := rd.(io.Closer); ok {
160157
return c.Close()
@@ -163,6 +160,9 @@ func (r *Request) close() error {
163160
if c, ok := wt.(io.Closer); ok {
164161
return c.Close()
165162
}
163+
if r.cancelCtx != nil {
164+
r.cancelCtx()
165+
}
166166
return nil
167167
}
168168

0 commit comments

Comments
 (0)
0