Fix Windows-specific race condition in syslogger. This could've been
authorHeikki Linnakangas <heikki@enterprisedb.com>
Wed, 18 Mar 2009 08:44:49 +0000 (08:44 +0000)
committerHeikki Linnakangas <heikki@enterprisedb.com>
Wed, 18 Mar 2009 08:44:49 +0000 (08:44 +0000)
the cause of the "could not write to log file: Bad file descriptor"
errors reported at
http://archives.postgresql.org//pgsql-general/2008-06/msg00193.php

Backpatch to 8.3, the race condition was introduced by the CSV logging
patch.

Analysis and patch by Gurjeet Singh.

src/backend/postmaster/syslogger.c

index 0f8d93a968b948e514c0fcf890702ba354a705e2..1b7c3bfa312d2fbedc0cc98868cfbc45e1271b5a 100644 (file)
@@ -907,13 +907,14 @@ write_syslogger_file(const char *buffer, int count, int destination)
        if (destination == LOG_DESTINATION_CSVLOG && csvlogFile == NULL)
                open_csvlogfile();
 
-       logfile = destination == LOG_DESTINATION_CSVLOG ? csvlogFile : syslogFile;
-
-#ifndef WIN32
-       rc = fwrite(buffer, 1, count, logfile);
-#else
+#ifdef WIN32
        EnterCriticalSection(&sysfileSection);
+#endif
+
+       logfile = destination == LOG_DESTINATION_CSVLOG ? csvlogFile : syslogFile;
        rc = fwrite(buffer, 1, count, logfile);
+
+#ifdef WIN32
        LeaveCriticalSection(&sysfileSection);
 #endif