From 27a34609a105e4e4088fd80f5bdc8c3a5ea4aee4 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 5 Feb 2021 11:21:14 +0100 Subject: [PATCH] all: Failure reporting fixes (#7331) --- cmd/stcrashreceiver/main.go | 2 +- lib/db/lowlevel.go | 2 +- lib/ur/failurereporting.go | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/stcrashreceiver/main.go b/cmd/stcrashreceiver/main.go index c7fb09b31..5cb58b034 100644 --- a/cmd/stcrashreceiver/main.go +++ b/cmd/stcrashreceiver/main.go @@ -47,7 +47,7 @@ func main() { mux.Handle("/", cr) if *dsn != "" { - mux.HandleFunc("/failure", handleFailureFn(*dsn)) + mux.HandleFunc("/newcrash/failure", handleFailureFn(*dsn)) } log.SetOutput(os.Stdout) diff --git a/lib/db/lowlevel.go b/lib/db/lowlevel.go index d384194bb..fa16705b9 100644 --- a/lib/db/lowlevel.go +++ b/lib/db/lowlevel.go @@ -1202,7 +1202,7 @@ func unchanged(nf, ef protocol.FileIntf) bool { func (db *Lowlevel) handleFailure(err error) { db.checkErrorForRepair(err) if shouldReportFailure(err) { - db.evLogger.Log(events.Failure, err) + db.evLogger.Log(events.Failure, err.Error()) } } diff --git a/lib/ur/failurereporting.go b/lib/ur/failurereporting.go index 28ef2e4df..91c6223cc 100644 --- a/lib/ur/failurereporting.go +++ b/lib/ur/failurereporting.go @@ -123,13 +123,15 @@ func (h *failureHandler) Serve(ctx context.Context) error { if sub != nil { sub.Unsubscribe() - reports := make([]FailureReport, 0, len(h.buf)) - for descr, stat := range h.buf { - reports = append(reports, newFailureReport(descr, stat.count)) + if len(h.buf) > 0 { + reports := make([]FailureReport, 0, len(h.buf)) + for descr, stat := range h.buf { + reports = append(reports, newFailureReport(descr, stat.count)) + } + timeout, cancel := context.WithTimeout(context.Background(), finalSendTimeout) + defer cancel() + sendFailureReports(timeout, reports, url) } - timeout, cancel := context.WithTimeout(context.Background(), finalSendTimeout) - defer cancel() - sendFailureReports(timeout, reports, url) } return err } @@ -192,7 +194,7 @@ func sendFailureReports(ctx context.Context, reports []FailureReport, url string reqCtx, reqCancel := context.WithTimeout(ctx, sendTimeout) defer reqCancel() - req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, url, &b) + req, err := http.NewRequestWithContext(reqCtx, http.MethodPost, url, &b) if err != nil { l.Infoln("Failed to send failure report:", err) return