gin: broken pipe (#538)

* broken pipe

* don't fail if release isn't here
This commit is contained in:
Thibault "bui" Koechlin 2020-12-14 17:48:32 +01:00 committed by GitHub
parent 1c005d6923
commit ad4521f2cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -66,7 +66,7 @@ clean:
@rm -f $(CROWDSEC_BIN)
@rm -f $(CSCLI_BIN)
@rm -f *.log
@rm crowdsec-release.tgz
@rm -f crowdsec-release.tgz
cscli:
ifeq ($(lastword $(RESPECT_VERSION)), $(CURRENT_GOVERSION))

View file

@ -13,6 +13,7 @@ import (
"runtime/debug"
"strconv"
"strings"
"syscall"
"time"
"github.com/crowdsecurity/crowdsec/pkg/cwversion"
@ -116,6 +117,17 @@ func Clone(a, b interface{}) error {
func CatchPanic(component string) {
if r := recover(); r != nil {
/*mimic gin's behaviour on broken pipe*/
var brokenPipe bool
if ne, ok := r.(*net.OpError); ok {
if se, ok := ne.Err.(*os.SyscallError); ok {
if se.Err == syscall.EPIPE || se.Err == syscall.ECONNRESET {
brokenPipe = true
}
}
}
tmpfile, err := ioutil.TempFile("/tmp/", "crowdsec-crash.*.txt")
if err != nil {
log.Fatal(err)
@ -131,10 +143,16 @@ func CatchPanic(component string) {
if err := tmpfile.Close(); err != nil {
log.Fatal(err)
}
log.Errorf("crowdsec - goroutine %s crashed : %s", component, r)
log.Errorf("please report this error to https://github.com/crowdsecurity/crowdsec/")
log.Errorf("stacktrace/report is written to %s : please join it to your issue", tmpfile.Name())
log.Fatalf("crowdsec stopped")
/*if it's not a broken pipe error, we don't want to fatal. it can happen from Local API pov*/
if !brokenPipe {
log.Fatalf("crowdsec stopped")
}
}
}