Skip to content

Commit 2d26b6c

Browse files
committed
windows: don't return, exit via exit(0) instead
This fixes a bug where output would not actually be written to stdout before exiting the process, leading to a flaky Windows CI. Exiting using `exit(0)` appears to fix this. For some background, see: #4589
1 parent 0087d4c commit 2d26b6c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/runtime/runtime_windows.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ func mainCRTStartup() int {
5252
stackTop = getCurrentStackPointer()
5353
runMain()
5454

55-
// For libc compatibility.
55+
// Exit via exit(0) instead of returning. This matches
56+
// mingw-w64-crt/crt/crtexe.c, which exits using exit(0) instead of
57+
// returning the return value.
58+
// Exiting this way (instead of returning) also fixes an issue where not all
59+
// output would be sent to stdout before exit.
60+
// See: https://github.com/tinygo-org/tinygo/pull/4589
61+
libc_exit(0)
62+
63+
// Unreachable, since we've already exited. But we need to return something
64+
// here to make this valid Go code.
5665
return 0
5766
}
5867

0 commit comments

Comments
 (0)