Possible data race on Windows (src/bin/pg_dump/parallel.c)

Started by Ranier Vilelaover 1 year ago1 messages
#1Ranier Vilela
ranier.vf@gmail.com
1 attachment(s)

Hi,

Per Coverity.

CID 1542943: (#1 of 1): Data race condition (MISSING_LOCK)
3. missing_lock: Accessing slot->AH without holding lock signal_info_lock.
Elsewhere, ParallelSlot.AH is written to with signal_info_lock held 1 out
of 1 times (1 of these accesses strongly imply that it is necessary).

The function DisconnectDatabase effectively writes the ParallelSlot.AH.
So the call in the function archive_close_connection:

if (slot->AH)
DisconnectDatabase(&(slot->AH->public));

It should also be protected on Windows, correct?

Patch attached.

best regards,
Ranier Vilela

Attachments:

fix-possible-data-race-windows-parallel.patchapplication/octet-stream; name=fix-possible-data-race-windows-parallel.patchDownload
diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
index a09247fae4..03c2b8e665 100644
--- a/src/bin/pg_dump/parallel.c
+++ b/src/bin/pg_dump/parallel.c
@@ -366,8 +366,14 @@ archive_close_connection(int code, void *arg)
 			 * fail to detect it because there would be no EOF condition on
 			 * the other end of the pipe.)
 			 */
+#ifdef WIN32
+			EnterCriticalSection(&signal_info_lock);
+#endif
 			if (slot->AH)
 				DisconnectDatabase(&(slot->AH->public));
+#ifdef WIN32
+			LeaveCriticalSection(&signal_info_lock);
+#endif
 
 #ifdef WIN32
 			closesocket(slot->pipeRevRead);