]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool and tests: force flush of all buffers at end of program
authorMarc Hoersken <info@marc-hoersken.de>
Sat, 26 Feb 2022 13:34:42 +0000 (14:34 +0100)
committerMarc Hoersken <info@marc-hoersken.de>
Sun, 13 Mar 2022 12:29:28 +0000 (13:29 +0100)
On Windows data can be lost in buffers in case of abnormal program
termination, especially in process chains as seen due to flaky tests.
Therefore flushing all buffers manually should avoid this data loss.

In the curl tool we play the safe game by only flushing write buffers,
but in the testsuite where we manage all buffers, we flush everything.

This should drastically reduce Windows CI and testsuite flakiness.

Reviewed-by: Daniel Stenberg
Supersedes #7833 and #6064
Closes #8516

src/tool_main.c
tests/libtest/first.c
tests/server/util.c
tests/server/util.h

index d6d8e9911a2f861755f529a488e2a3cb504c66bc..8a2f4d6cbbca831a9a875ed569029a1fc561de74 100644 (file)
@@ -277,6 +277,11 @@ int main(int argc, char *argv[])
     main_free(&global);
   }
 
+#ifdef WIN32
+  /* Flush buffers of all streams opened in write or update mode */
+  fflush(NULL);
+#endif
+
 #ifdef __NOVELL_LIBC__
   if(!getenv("_IN_NETWARE_BASH_"))
     tool_pressanykey();
index ffb211fd47d03456b7113d2d0dd5152d00090678..4ba0fab60bdbfe40090051b7de8272dce56083ba 100644 (file)
@@ -179,5 +179,10 @@ int main(int argc, char **argv)
     PR_Cleanup();
 #endif
 
+#ifdef WIN32
+  /* flush buffers of all streams regardless of mode */
+  _flushall();
+#endif
+
   return result;
 }
index cfa8be28571c87e625cc877bfd4ef21e4b875134..3b98e71660282bd98d0cd8d548137fe26d23736e 100644 (file)
@@ -159,11 +159,10 @@ void win32_perror(const char *msg)
     fprintf(stderr, "%s: ", msg);
   fprintf(stderr, "%s\n", buf);
 }
-#endif  /* WIN32 */
 
-#ifdef USE_WINSOCK
 void win32_init(void)
 {
+#ifdef USE_WINSOCK
   WORD wVersionRequested;
   WSADATA wsaData;
   int err;
@@ -184,14 +183,20 @@ void win32_init(void)
     logmsg("No suitable winsock.dll found -- aborting");
     exit(1);
   }
+#endif  /* USE_WINSOCK */
 }
 
 void win32_cleanup(void)
 {
+#ifdef USE_WINSOCK
   WSACleanup();
-}
 #endif  /* USE_WINSOCK */
 
+  /* flush buffers of all streams regardless of their mode */
+  _flushall();
+}
+#endif  /* WIN32 */
+
 /* set by the main code to point to where the test dir is */
 const char *path = ".";
 
index 140e349f38c841155c6f459900ed9a52c4b31ef9..ae05b5935022c9e4e7a54db28daee24b49fd27d1 100644 (file)
@@ -51,10 +51,10 @@ extern const char *cmdfile;
 void win32_perror(const char *msg);
 #endif  /* WIN32 or _WIN32 */
 
-#ifdef USE_WINSOCK
+#ifdef WIN32
 void win32_init(void);
 void win32_cleanup(void);
-#endif  /* USE_WINSOCK */
+#endif  /* WIN32 */
 
 /* fopens the test case file */
 FILE *test2fopen(long testno);