@@ -217,9 +217,7 @@ func testCancel(t *testing.T, ignore bool) {
217
217
// Either way, this should undo both calls to Notify above.
218
218
if ignore {
219
219
Ignore (syscall .SIGWINCH , syscall .SIGHUP )
220
- // Don't bother deferring a call to Reset: it is documented to undo Notify,
221
- // but its documentation says nothing about Ignore, and (as of the time of
222
- // writing) it empirically does not undo an Ignore.
220
+ defer Reset (syscall .SIGWINCH , syscall .SIGHUP )
223
221
} else {
224
222
Reset (syscall .SIGWINCH , syscall .SIGHUP )
225
223
}
@@ -913,3 +911,61 @@ func TestSignalTrace(t *testing.T) {
913
911
close (quit )
914
912
<- done
915
913
}
914
+
915
+ // #46321 test Reset actually undoes the effect of Ignore.
916
+ func TestResetIgnore (t * testing.T ) {
917
+ if os .Getenv ("GO_TEST_RESET_IGNORE" ) != "" {
918
+ s , err := strconv .Atoi (os .Getenv ("GO_TEST_RESET_IGNORE" ))
919
+ if err != nil {
920
+ t .Fatalf ("failed to parse signal: %v" , err )
921
+ }
922
+ resetIgnoreTestProgram (t , syscall .Signal (s ))
923
+ }
924
+
925
+ sigs := []syscall.Signal {
926
+ syscall .SIGINT ,
927
+ syscall .SIGHUP ,
928
+ syscall .SIGUSR1 ,
929
+ syscall .SIGTERM ,
930
+ syscall .SIGCHLD ,
931
+ syscall .SIGWINCH ,
932
+ }
933
+
934
+ for _ , notify := range []bool {false , true } {
935
+ for _ , sig := range sigs {
936
+ t .Run (fmt .Sprintf ("%s[notify=%t]" , sig , notify ), func (t * testing.T ) {
937
+ Ignore (sig )
938
+ if notify {
939
+ c := make (chan os.Signal , 1 )
940
+ Notify (c , sig )
941
+ defer Stop (c )
942
+ }
943
+ Reset (sig )
944
+
945
+ if Ignored (sig ) {
946
+ t .Fatalf ("expected %q to not be ignored" , sig )
947
+ }
948
+
949
+ // Child processes inherit the ignored status of signals, so verify that it
950
+ // is indeed not ignored.
951
+ testenv .MustHaveExec (t )
952
+
953
+ cmd := testenv .Command (t , os .Args [0 ], "-test.run=^TestResetIgnore$" )
954
+ cmd .Env = append (os .Environ (), "GO_TEST_RESET_IGNORE=" + strconv .Itoa (int (sig )))
955
+ err := cmd .Run ()
956
+ if _ , ok := err .(* exec.ExitError ); ok {
957
+ t .Fatalf ("expected %q to not be ignored in child process" , sig )
958
+ } else if err != nil {
959
+ t .Fatalf ("child process failed to launch: %v" , err )
960
+ }
961
+ })
962
+ }
963
+ }
964
+ }
965
+
966
+ func resetIgnoreTestProgram (t * testing.T , sig os.Signal ) {
967
+ if Ignored (sig ) {
968
+ os .Exit (1 )
969
+ }
970
+ os .Exit (0 )
971
+ }
0 commit comments