From: Amos Jeffries Date: Mon, 29 Oct 2012 02:17:18 +0000 (-0600) Subject: Bug 3189: AIO thread race on pipe() initialization X-Git-Tag: SQUID_3_4_0_1~543 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45bb03812cb68af775325092731082b5485e9dce;p=thirdparty%2Fsquid.git Bug 3189: AIO thread race on pipe() initialization --- diff --git a/src/DiskIO/DiskThreads/CommIO.cc b/src/DiskIO/DiskThreads/CommIO.cc index 3e4e23bf43..6112f2a8ad 100644 --- a/src/DiskIO/DiskThreads/CommIO.cc +++ b/src/DiskIO/DiskThreads/CommIO.cc @@ -41,13 +41,16 @@ 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); diff --git a/src/DiskIO/DiskThreads/CommIO.h b/src/DiskIO/DiskThreads/CommIO.h index b19e0c6711..2d51f70897 100644 --- a/src/DiskIO/DiskThreads/CommIO.h +++ b/src/DiskIO/DiskThreads/CommIO.h @@ -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; diff --git a/src/DiskIO/DiskThreads/aiops.cc b/src/DiskIO/DiskThreads/aiops.cc index b3ae20d93d..1269c27d0b 100644 --- a/src/DiskIO/DiskThreads/aiops.cc +++ b/src/DiskIO/DiskThreads/aiops.cc @@ -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));