Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 244FF633BC8 for ; Mon, 3 Aug 2009 11:38:01 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 18082-09 for ; Mon, 3 Aug 2009 14:37:41 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og105.obsmtp.com (exprod7og105.obsmtp.com [64.18.2.163]) by mail.postgresql.org (Postfix) with SMTP id 8D7CC6339AC for ; Mon, 3 Aug 2009 11:37:48 -0300 (ADT) Received: from source ([209.85.222.193]) by exprod7ob105.postini.com ([64.18.6.12]) with SMTP ID DSNKSnb2OjQSsEKAAKgjohRBj68LZgLIN3GG@postini.com; Mon, 03 Aug 2009 07:37:47 PDT Received: by pzk31 with SMTP id 31so3894677pzk.3 for ; Mon, 03 Aug 2009 07:37:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.173.19 with SMTP id v19mr476544wfe.310.1249310266267; Mon, 03 Aug 2009 07:37:46 -0700 (PDT) In-Reply-To: <9837222c0908030730kd59b9c2v7583666c5716aead@mail.gmail.com> References: <200907311459.n6VExuSa036743@wwwmaster.postgresql.org> <20090731234901.GD11098@alvh.no-ip.org> <9837222c0908010828x7182494av3fd5909b64f4b2ad@mail.gmail.com> <9837222c0908030656m6ed69a26gc90a6c94b41a4c47@mail.gmail.com> <9837222c0908030716r416d789ewef3f77c65b39d916@mail.gmail.com> <9837222c0908030730kd59b9c2v7583666c5716aead@mail.gmail.com> Date: Mon, 3 Aug 2009 20:07:46 +0530 Message-ID: Subject: Re: BUG #4958: Stats collector hung on WaitForMultipleObjectsEx while attempting to recv a datagram From: Nikhil Sontakke To: Magnus Hagander Cc: Alvaro Herrera , Luke Koops , pgsql-bugs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.821 tagged_above=-10 required=5 tests=AWL=0.778, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/10 X-Sequence-Number: 23837 Hi, >>>>> >>>>> Maybe. I'm unsure if it's enough to just try another >>>>> WaitForSingleObjectEx() on it, or if we need to actually issue a >>>>> WSARecv() on it as well. Maybe it would be enough to just change the >>>>> INIFINTE on line 318 of socket.c to a fixed value. That will loop down >>>>> to WSARecv() which should exit with WSAEWOULDBLOCK which will cause us >>>>> to do a short sleep and come back. But we'd have to change the limit >>>>> of 5 somehow then, since in theory we should wait forever. Maybe that >>>>> outer loop should just be a for(;;), what do you think? >>>>> >>>> >>>> Yes, line 318 seems to be a much better location to me. If Windows and >>>> it's socket logic behaves properly most of the times :), most of the >>>> calls should come out within the first few tries, so changing 5 to an >>>> infinite loop shouldn't hurt those normal use cases in theory. >>>> >>>> OTOH, I was wondering what if we kill the stats collector and on a >>>> restart the socket communication resumes properly. Would that >>>> conclusively mean that it is a flaw in our code? >>> >>> No, if we kill the stats collector that will destroy all sockets, and >>> when the new one starts all the sockets it operates on are fresh and >>> new. So it doesn't show that the flaw is in our code - but it also >>> doesn't show that it's in the kernel or runtime libraries. >>> >> >> AFAICS in the code, the inherited pgStatSock socket FD remains the >> same across the restart of the stats collector process... > > Partially correct, I think. > > Each backend has it's own handle on win32, since we use EXEC_BACKEND > (this includes the "utility processes" like the stats collector). When > we start the new one, we are going to use DuplicateHandle() in > save_backend_variables(). This will therefor get it a new handle, but > they are both pointing to the same kernel object. I don't know if > WaitForMultipleObjectsEx() is going to see these as two different > objects or not, but I think it does. > Hmm, got it. Nothing like adding more confusion into the mix :) Regards, Nikhils -- http://www.enterprisedb.com