Sfoglia il codice sorgente

gin: broken pipe (#538)

* broken pipe

* don't fail if release isn't here
Thibault "bui" Koechlin 4 anni fa
parent
commit
ad4521f2cc
2 ha cambiato i file con 20 aggiunte e 2 eliminazioni
  1. 1 1
      Makefile
  2. 19 1
      pkg/types/utils.go

+ 1 - 1
Makefile

@@ -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))

+ 19 - 1
pkg/types/utils.go

@@ -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")
+		}
+
 	}
 }