Skip to content

Commit 3f21c23

Browse files
os/signal: don't ignore SIGINT in TestAtomicStop child process
Fixes #35085 Change-Id: Ice611e1223392f687061a43fd4c2298ea22774fb Reviewed-on: https://go-review.googlesource.com/c/go/+/207081 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent e77106c commit 3f21c23

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/os/signal/signal_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,19 @@ func TestAtomicStop(t *testing.T) {
422422

423423
testenv.MustHaveExec(t)
424424

425+
// Call Notify for SIGINT before starting the child process.
426+
// That ensures that SIGINT is not ignored for the child.
427+
// This is necessary because if SIGINT is ignored when a
428+
// Go program starts, then it remains ignored, and closing
429+
// the last notification channel for SIGINT will switch it
430+
// back to being ignored. In that case the assumption of
431+
// atomicStopTestProgram, that it will either die from SIGINT
432+
// or have it be reported, breaks down, as there is a third
433+
// option: SIGINT might be ignored.
434+
cs := make(chan os.Signal, 1)
435+
Notify(cs, syscall.SIGINT)
436+
defer Stop(cs)
437+
425438
const execs = 10
426439
for i := 0; i < execs; i++ {
427440
timeout := "0"
@@ -466,6 +479,12 @@ func TestAtomicStop(t *testing.T) {
466479
// It tries to trigger a signal delivery race. This function should
467480
// either catch a signal or die from it.
468481
func atomicStopTestProgram() {
482+
// This test won't work if SIGINT is ignored here.
483+
if Ignored(syscall.SIGINT) {
484+
fmt.Println("SIGINT is ignored")
485+
os.Exit(1)
486+
}
487+
469488
const tries = 10
470489

471490
timeout := 2 * time.Second

0 commit comments

Comments
 (0)