gin: broken pipe (#538)
* broken pipe * don't fail if release isn't here
This commit is contained in:
parent
1c005d6923
commit
ad4521f2cc
2
Makefile
2
Makefile
|
@ -66,7 +66,7 @@ clean:
|
||||||
@rm -f $(CROWDSEC_BIN)
|
@rm -f $(CROWDSEC_BIN)
|
||||||
@rm -f $(CSCLI_BIN)
|
@rm -f $(CSCLI_BIN)
|
||||||
@rm -f *.log
|
@rm -f *.log
|
||||||
@rm crowdsec-release.tgz
|
@rm -f crowdsec-release.tgz
|
||||||
|
|
||||||
cscli:
|
cscli:
|
||||||
ifeq ($(lastword $(RESPECT_VERSION)), $(CURRENT_GOVERSION))
|
ifeq ($(lastword $(RESPECT_VERSION)), $(CURRENT_GOVERSION))
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/cwversion"
|
"github.com/crowdsecurity/crowdsec/pkg/cwversion"
|
||||||
|
@ -116,6 +117,17 @@ func Clone(a, b interface{}) error {
|
||||||
func CatchPanic(component string) {
|
func CatchPanic(component string) {
|
||||||
|
|
||||||
if r := recover(); r != nil {
|
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")
|
tmpfile, err := ioutil.TempFile("/tmp/", "crowdsec-crash.*.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -131,11 +143,17 @@ func CatchPanic(component string) {
|
||||||
if err := tmpfile.Close(); err != nil {
|
if err := tmpfile.Close(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Errorf("crowdsec - goroutine %s crashed : %s", component, r)
|
log.Errorf("crowdsec - goroutine %s crashed : %s", component, r)
|
||||||
log.Errorf("please report this error to https://github.com/crowdsecurity/crowdsec/")
|
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.Errorf("stacktrace/report is written to %s : please join it to your issue", tmpfile.Name())
|
||||||
|
|
||||||
|
/*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")
|
log.Fatalf("crowdsec stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseDuration(d string) (time.Duration, error) {
|
func ParseDuration(d string) (time.Duration, error) {
|
||||||
|
|
Loading…
Reference in a new issue