bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.37k stars 651 forks source link

bzltestutil: restore timeout signal handler #3929

Closed sluongng closed 5 months ago

sluongng commented 5 months ago

In https://github.com/bazelbuild/rules_go/pull/3920, a new mechanism to handle test timeout was introduced. However this broke existing tests that use SIGTERM inside.

Restore the original behavior.


From the doc of signal.Ignore:

// Ignore causes the provided signals to be ignored. If they are received by
// the program, nothing will happen. Ignore undoes the effect of any prior
// calls to Notify for the provided signals.
// If no signals are provided, all incoming signals will be ignored.

so what it does is to iterate over signal.handlers.m, a package-level map variable that keeps track of all the signal -> channel that it needs to notify upon receiving a signal. Upon finding the right entries for the given signal, it will delete all the handlers for that signal.

This does not work for us because we have never called signal.Notify before signal.Ignore, thus the call to signal.Ignore deleted no handler and was effectively a no-ops. Using signal.Notify to first register a handler to capture the signal is the right fix.

Reference: https://cs.opensource.google/go/go/+/refs/tags/go1.22.2:src/os/signal/signal.go;l=86

sluongng commented 5 months ago

@linzhp FYI