@@ -11,26 +11,26 @@ import (
11
11
)
12
12
13
13
func main () {
14
- // ensure that this process terminates when the test times out,
15
- // even if the expected signal never arrives
14
+ // Ensure that this process terminates when the test times out,
15
+ // even if the expected signal never arrives.
16
16
go func () {
17
17
io .Copy (io .Discard , os .Stdin )
18
18
log .Fatal ("stdin is closed; terminating" )
19
19
}()
20
20
21
- // register to receive all signals
21
+ // Register to receive all signals.
22
22
c := make (chan os.Signal , 1 )
23
23
signal .Notify (c )
24
24
25
- // get console window handle
25
+ // Get console window handle.
26
26
kernel32 := syscall .NewLazyDLL ("kernel32.dll" )
27
27
getConsoleWindow := kernel32 .NewProc ("GetConsoleWindow" )
28
28
hwnd , _ , err := getConsoleWindow .Call ()
29
29
if hwnd == 0 {
30
30
log .Fatal ("no associated console: " , err )
31
31
}
32
32
33
- // close console window
33
+ // Send message to close the console window.
34
34
const _WM_CLOSE = 0x0010
35
35
user32 := syscall .NewLazyDLL ("user32.dll" )
36
36
postMessage := user32 .NewProc ("PostMessageW" )
@@ -40,8 +40,14 @@ func main() {
40
40
}
41
41
42
42
sig := <- c
43
- // pretend to take some time handling the signal
43
+
44
+ // Allow some time for the handler to complete if it's going to.
45
+ //
46
+ // (In https://go.dev/issue/41884 the handler returned immediately,
47
+ // which caused Windows to terminate the program before the goroutine
48
+ // that received the SIGTERM had a chance to actually clean up.)
44
49
time .Sleep (time .Second )
45
- // print signal name, "terminated" makes the test succeed
50
+
51
+ // Print the signal's name: "terminated" makes the test succeed.
46
52
fmt .Println (sig )
47
53
}
0 commit comments