Skip to content

Commit

Permalink
recovery: fix issue about syscall import on google app engine (#1640)
Browse files Browse the repository at this point in the history
* recovery: fix issue about syscall import on google app engine

* add ToLower()

* the whole error message
  • Loading branch information
thinkerou authored and appleboy committed Nov 22, 2018
1 parent 3d44ff8 commit 7ec82ee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"net/http/httputil"
"os"
"runtime"
"syscall"
"strings"
"time"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ func RecoveryWithWriter(out io.Writer) HandlerFunc {
var brokenPipe bool
if ne, ok := err.(*net.OpError); ok {
if se, ok := ne.Err.(*os.SyscallError); ok {
if se.Err == syscall.EPIPE || se.Err == syscall.ECONNRESET {
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") {
brokenPipe = true
}
}
Expand Down
4 changes: 2 additions & 2 deletions recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func TestPanicWithBrokenPipe(t *testing.T) {
const expectCode = 204

expectMsgs := map[syscall.Errno]string{
syscall.EPIPE: "broken pipe",
syscall.ECONNRESET: "connection reset",
syscall.EPIPE: "Broken pipe",
syscall.ECONNRESET: "connection reset by peer",
}

for errno, expectMsg := range expectMsgs {
Expand Down

0 comments on commit 7ec82ee

Please sign in to comment.