------------------------------------------------------------ revno: 11698 revision-id: squid3@treenet.co.nz-20121110043729-xqf2btt96xgqjut6 parent: squid3@treenet.co.nz-20121110043325-3yr23vr0oah4n1rc fixes bug(s): http://bugs.squid-cache.org/show_bug.cgi?id=3189 committer: Amos Jeffries branch nick: 3.2 timestamp: Fri 2012-11-09 21:37:29 -0700 message: Bug 3189: AIO thread race on pipe() initialization ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20121110043729-xqf2btt96xgqjut6 # target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\ # /SQUID_3_2 # testament_sha1: a67aaf003c3b2c0a7b55fcb836be0fd7d3e3e90e # timestamp: 2012-11-10 04:40:00 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\ # /SQUID_3_2 # base_revision_id: squid3@treenet.co.nz-20121110043325-\ # 3yr23vr0oah4n1rc # # Begin patch === modified file 'src/DiskIO/DiskThreads/CommIO.cc' --- src/DiskIO/DiskThreads/CommIO.cc 2012-06-04 10:49:01 +0000 +++ src/DiskIO/DiskThreads/CommIO.cc 2012-11-10 04:37:29 +0000 @@ -38,19 +38,22 @@ #include "DiskIO/DiskThreads/CommIO.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 @@ -62,10 +65,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-02-25 04:14:25 +0000 +++ src/DiskIO/DiskThreads/CommIO.h 2012-11-10 04:37:29 +0000 @@ -9,25 +9,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-07-28 05:38:50 +0000 +++ src/DiskIO/DiskThreads/aiops.cc 2012-11-10 04:37:29 +0000 @@ -308,6 +308,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));