------------------------------------------------------------ revno: 12380 revision-id: squid3@treenet.co.nz-20121110040252-njww6vm5k04c87nc parent: squid3@treenet.co.nz-20121110035744-ytrkuj55aj9vt0f8 fixes bug(s): http://bugs.squid-cache.org/show_bug.cgi?id=3189 committer: Amos Jeffries branch nick: 3.3 timestamp: Fri 2012-11-09 21:02:52 -0700 message: Bug 3189: AIO thread race on pipe() initialization ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20121110040252-njww6vm5k04c87nc # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # testament_sha1: 8bc61e1cb96eb428703b1b3d7f90a6ccffcf7d7c # timestamp: 2012-11-10 04:03:37 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # base_revision_id: squid3@treenet.co.nz-20121110035744-\ # ytrkuj55aj9vt0f8 # # Begin patch === modified file 'src/DiskIO/DiskThreads/CommIO.cc' --- src/DiskIO/DiskThreads/CommIO.cc 2012-08-31 16:57:39 +0000 +++ src/DiskIO/DiskThreads/CommIO.cc 2012-11-10 04:02:52 +0000 @@ -39,19 +39,22 @@ #include "globals.h" void -CommIO::Initialise() +CommIO::Initialize() { + if (CommIO::Initialized) + 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); - Initialised = true; + Initialized = true; } void @@ -63,10 +66,10 @@ close(DoneReadFD); fd_close(DoneFD); fd_close(DoneReadFD); - Initialised = false; + Initialized = false; } -bool CommIO::Initialised = false; +bool CommIO::Initialized = false; bool CommIO::DoneSignalled = false; int CommIO::DoneFD = -1; int CommIO::DoneReadFD = -1; === modified file 'src/DiskIO/DiskThreads/CommIO.h' --- src/DiskIO/DiskThreads/CommIO.h 2012-08-28 13:00:30 +0000 +++ src/DiskIO/DiskThreads/CommIO.h 2012-11-10 04:02:52 +0000 @@ -10,24 +10,25 @@ public: static inline void NotifyIOCompleted(); static void ResetNotifications(); - static void Initialise(); + static void Initialize(); static void NotifyIOClose(); private: static void NULLFDHandler(int, void *); static void FlushPipe(); - static bool Initialised; + static bool Initialized; static bool DoneSignalled; static int DoneFD; 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 (!Initialized) { + fatalf("Disk Threads I/O pipes not initialized before first use."); + } if (!DoneSignalled) { DoneSignalled = true; === modified file 'src/DiskIO/DiskThreads/aiops.cc' --- src/DiskIO/DiskThreads/aiops.cc 2012-10-03 17:32:57 +0000 +++ src/DiskIO/DiskThreads/aiops.cc 2012-11-10 04:02:52 +0000 @@ -306,6 +306,10 @@ 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));