From 56bf17fa8e6e8046474afd792127f28d1679d0ad Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Fri, 29 Nov 2024 09:39:43 -0800 Subject: [PATCH] [v1.4.1] Allow disable crash --- internal/http/server.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/http/server.go b/internal/http/server.go index cba0bcb..e73d348 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -32,10 +32,11 @@ type Server struct { func (s *Server) HandleHTTP(w http.ResponseWriter, r *http.Request) { s.logger.Info("inbound", "method", r.Method, "url", r.URL.Path, "host", r.Host, "proto", r.Proto, "agent", r.UserAgent(), "peer", r.RemoteAddr, "counter", s.counter.Load()) + newCount := s.counter.Add(1) - if newValue := s.counter.Add(1); newValue%s.frequency == 0 { - s.logger.Warn("crash", "counter", newValue) - panic("crash after 10 requests") + if s.frequency != 0 && newCount%s.frequency == 0 { + s.logger.Warn("crash", "counter", newCount) + panic("crash as requested") } s.logger.Info("outbound", "status", 200)