pingcap / failpoint

An implementation of failpoints for Golang.
Apache License 2.0
817 stars 63 forks source link

failpoint.Disable should be idempotent #75

Closed tisonkun closed 2 years ago

tisonkun commented 2 years ago

For example, I may register a defer block to disable failpoint to ensure that it's triggered no matter intermediate error occurs, while I'm going to disable the failpoint on the fly of the code flow early to switch behavior.

Then, one failpoint can be disabled twice and with current implementation, this causes failpoint: failpoint is disabled error.

func foo() {
    failpoint.Enable(...)
    defer failpoint.Disable(...)
    // ... error may occur in this block, thus I need a defer block above
    failpoint.Disable(...)
    // failpoint has been disabled, but it will be disable again when executing the defer block
}

I'd like to make failpoint.Disable idempotent.

What do you think @lonng @kennytm?

lonng commented 2 years ago

@tisonkun Make sense.