]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3189: AIO thread race on pipe() initialization
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 29 Oct 2012 02:17:18 +0000 (20:17 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 29 Oct 2012 02:17:18 +0000 (20:17 -0600)
src/DiskIO/DiskThreads/CommIO.cc
src/DiskIO/DiskThreads/CommIO.h
src/DiskIO/DiskThreads/aiops.cc

index 3e4e23bf4361fa396737884a53e705b1efd12254..6112f2a8ad44e6a387788f5a3b0911793d95461c 100644 (file)
 void
 CommIO::Initialise()
 {
+    if (CommIO::Initialised)
+        return;
+
     /* Initialize done pipe signal */
     int DonePipe[2];
     if (pipe(DonePipe)) {}
     DoneFD = DonePipe[1];
     DoneReadFD = DonePipe[0];
-    fd_open(DoneReadFD, FD_PIPE, "async-io completetion event: main");
-    fd_open(DoneFD, FD_PIPE, "async-io completetion event: threads");
+    fd_open(DoneReadFD, FD_PIPE, "async-io completion event: main");
+    fd_open(DoneFD, FD_PIPE, "async-io completion event: threads");
     commSetNonBlocking(DoneReadFD);
     commSetNonBlocking(DoneFD);
     Comm::SetSelect(DoneReadFD, COMM_SELECT_READ, NULLFDHandler, NULL, 0);
index b19e0c6711804721a18a812a7cf3efaa38b2d3fb..2d51f70897f27e4628cacf112e358da0c67d6cd2 100644 (file)
@@ -22,12 +22,13 @@ private:
     static int DoneReadFD;
 };
 
-/* Inline code. TODO: make structued approach to inlining */
+/* Inline code. TODO: make structured approach to inlining */
 void
 CommIO::NotifyIOCompleted()
 {
-    if (!Initialised)
-        Initialise();
+    if (!Initialised) {
+        fatalf("Disk Threads I/O pipes not initialized before first use.");
+    }
 
     if (!DoneSignalled) {
         DoneSignalled = true;
index b3ae20d93df1f21a6d6387acb33a4efcffe0656e..1269c27d0bb77676fb53a837bbe9407e542f8b56 100644 (file)
@@ -306,6 +306,10 @@ squidaio_init(void)
 
     done_queue.blocked = 0;
 
+    // Initialize the thread I/O pipes before creating any threads
+    // see bug 3189 comment 5 about race conditions.
+    CommIO::Initialize();
+
     /* Create threads and get them to sit in their wait loop */
     squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t));