1
// Copyright 2022 The CubeFS Authors.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
26
"github.com/cubefs/cubefs/blobstore/util/log"
29
// defaultRecovery logging panic info, then panic to next handler
30
func defaultRecovery(w http.ResponseWriter, req *http.Request, err interface{}) {
32
if ne, ok := err.(*net.OpError); ok {
33
if se, ok := ne.Err.(*os.SyscallError); ok {
34
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") ||
35
strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") {
43
log.Warnf("handle panic: %s on broken pipe\n%s", err, stack)
45
log.Errorf("handle panic: %s\n%s", err, stack)
50
func stack(skip int) []byte {
51
buf := new(bytes.Buffer)
52
for i := skip; ; i++ {
53
pc, file, line, ok := runtime.Caller(i)
57
fmt.Fprintf(buf, "%s:%d (0x%x:%s)\n", file, line, pc, funcname(pc))
62
// funcname returns the name of the function
63
func funcname(pc uintptr) []byte {
64
fn := runtime.FuncForPC(pc)
68
name := []byte(fn.Name())
70
if last := bytes.LastIndex(name, []byte("/")); last >= 0 {
73
if first := bytes.Index(name, []byte(".")); first >= 0 {