mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Close stream on panic (#13605)
Always close streamHTTPResponse on panic on main thread to avoid write/flush after response handler has returned.
This commit is contained in:
parent
9afdbe3648
commit
4f3317effe
@ -19,9 +19,11 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"runtime/debug"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -357,6 +359,12 @@ func (s *storageRESTServer) WalkDirHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
prefix := r.Form.Get(storageRESTPrefixFilter)
|
prefix := r.Form.Get(storageRESTPrefixFilter)
|
||||||
forward := r.Form.Get(storageRESTForwardFilter)
|
forward := r.Form.Get(storageRESTForwardFilter)
|
||||||
writer := streamHTTPResponse(w)
|
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{
|
writer.CloseWithError(s.storage.WalkDir(r.Context(), WalkDirOptions{
|
||||||
Bucket: volume,
|
Bucket: volume,
|
||||||
BaseDir: dirPath,
|
BaseDir: dirPath,
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -177,6 +178,12 @@ func (s *storageRESTServer) NSScannerHandler(w http.ResponseWriter, r *http.Requ
|
|||||||
ctx, cancel := context.WithCancel(r.Context())
|
ctx, cancel := context.WithCancel(r.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
resp := streamHTTPResponse(w)
|
resp := streamHTTPResponse(w)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
debug.PrintStack()
|
||||||
|
resp.CloseWithError(fmt.Errorf("panic: %v", r))
|
||||||
|
}
|
||||||
|
}()
|
||||||
respW := msgp.NewWriter(resp)
|
respW := msgp.NewWriter(resp)
|
||||||
|
|
||||||
// Collect updates, stream them before the full cache is sent.
|
// Collect updates, stream them before the full cache is sent.
|
||||||
|
Loading…
Reference in New Issue
Block a user