From 19d819d49c73c8e47749b3c4cbbc2e58a259269a Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 24 Jan 2022 09:27:31 -0500 Subject: [PATCH] runtime: call fflush before exiting in C test Very, very rarely TestVectoredHandlerDontCrashOnLibrary fails because the C subprocess exits with a 0 status code and no output. This appears to happen because C does not actually guarantee that stdout will be flushed on exit and somehow, very rarely, it is not flushed. Add explicit fflushes to fix this. This reduces the failure rate of TestVectoredHandlerDontCrashOnLibrary from 0.0013% to 0% in 250,000 iterations. Fixes #49959. Change-Id: I892cf49a165ac91134c5da37588a2ab11e1f3f8b Reviewed-on: https://go-review.googlesource.com/c/go/+/380494 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/runtime/testdata/testwinlib/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtime/testdata/testwinlib/main.c b/src/runtime/testdata/testwinlib/main.c index e84a32f753..c3fe3cb071 100644 --- a/src/runtime/testdata/testwinlib/main.c +++ b/src/runtime/testdata/testwinlib/main.c @@ -41,17 +41,20 @@ int main() if (NULL == exceptionHandlerHandle) { printf("cannot add vectored exception handler\n"); + fflush(stdout); return 2; } void *continueHandlerHandle = AddVectoredContinueHandler(0, customContinueHandlder); if (NULL == continueHandlerHandle) { printf("cannot add vectored continue handler\n"); + fflush(stdout); return 2; } CallMeBack(throwFromC); RemoveVectoredContinueHandler(continueHandlerHandle); RemoveVectoredExceptionHandler(exceptionHandlerHandle); printf("exceptionCount: %d\ncontinueCount: %d\n", exceptionCount, continueCount); + fflush(stdout); return 0; -} \ No newline at end of file +} -- 2.50.0