Skip to content

Commit

Permalink
Add comments regarding failpointsMu and panicMu
Browse files Browse the repository at this point in the history
Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
Co-authored-by: Marek Siarkowicz <marek.siarkowicz@protonmail.com>
  • Loading branch information
henrybear327 and serathius committed May 15, 2024
1 parent 60b65e2 commit 13d483e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion runtime/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 7 additions & 1 deletion runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit 13d483e

Please sign in to comment.