From 13d483e268529eebe679f613f71cc8454c8775d2 Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Wed, 15 May 2024 21:40:20 +0200 Subject: [PATCH] Add comments regarding failpointsMu and panicMu Signed-off-by: Chun-Hung Tseng Co-authored-by: Marek Siarkowicz --- runtime/http.go | 4 +++- runtime/runtime.go | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/http.go b/runtime/http.go index f006869..84ecaf7 100644 --- a/runtime/http.go +++ b/runtime/http.go @@ -38,7 +38,9 @@ func serve(host string) error { func (*httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Ensures the server(runtime) doesn't panic due to the execution of - // panic failpoints during processing of the HTTP request + // panic failpoints during processing of the HTTP request, as the + // sender of the HTTP request should not be affected by the execution + // of the panic failpoints and crash as a side effect panicMu.Lock() defer panicMu.Unlock() diff --git a/runtime/runtime.go b/runtime/runtime.go index 3230fb6..f6e1589 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -25,11 +25,17 @@ var ( ErrNoExist = fmt.Errorf("failpoint: failpoint does not exist") ErrDisabled = fmt.Errorf("failpoint: failpoint is disabled") - failpoints map[string]*Failpoint + failpoints map[string]*Failpoint + // failpointsMu protects the failpoints map, preventing concurrent + // accesses during commands such as Enabling and Disabling failpointsMu sync.RWMutex envTerms map[string]string + // panicMu (panic mutex) ensures that the action of panic failpoints + // and serving of the HTTP requests won't be executed at the same time, + // avoiding the possibility that the server runtime panics during processing + // requests panicMu sync.Mutex )