Browse Source
Close stream on panic (#13605)
Always close streamHTTPResponse on panic on main thread to avoid
write/flush after response handler has returned.
pull/13609/head
Klaus Post
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
15 additions and
0 deletions
-
cmd/metacache-walk.go
-
cmd/storage-rest-server.go
|
|
@ -19,9 +19,11 @@ package cmd |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"runtime/debug" |
|
|
|
"sort" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
@ -357,6 +359,12 @@ func (s *storageRESTServer) WalkDirHandler(w http.ResponseWriter, r *http.Reques |
|
|
|
prefix := r.Form.Get(storageRESTPrefixFilter) |
|
|
|
forward := r.Form.Get(storageRESTForwardFilter) |
|
|
|
writer := streamHTTPResponse(w) |
|
|
|
defer func() { |
|
|
|
if r := recover(); r != nil { |
|
|
|
debug.PrintStack() |
|
|
|
writer.CloseWithError(fmt.Errorf("panic: %v", r)) |
|
|
|
} |
|
|
|
}() |
|
|
|
writer.CloseWithError(s.storage.WalkDir(r.Context(), WalkDirOptions{ |
|
|
|
Bucket: volume, |
|
|
|
BaseDir: dirPath, |
|
|
|
|
|
@ -30,6 +30,7 @@ import ( |
|
|
|
"net/http" |
|
|
|
"os/user" |
|
|
|
"path" |
|
|
|
"runtime/debug" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"sync" |
|
|
@ -177,6 +178,12 @@ func (s *storageRESTServer) NSScannerHandler(w http.ResponseWriter, r *http.Requ |
|
|
|
ctx, cancel := context.WithCancel(r.Context()) |
|
|
|
defer cancel() |
|
|
|
resp := streamHTTPResponse(w) |
|
|
|
defer func() { |
|
|
|
if r := recover(); r != nil { |
|
|
|
debug.PrintStack() |
|
|
|
resp.CloseWithError(fmt.Errorf("panic: %v", r)) |
|
|
|
} |
|
|
|
}() |
|
|
|
respW := msgp.NewWriter(resp) |
|
|
|
|
|
|
|
// Collect updates, stream them before the full cache is sent.
|
|
|
|