Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coU6y-0000iZ-5o for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Mar 2017 12:02:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1coU6x-0006hC-P1 for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Mar 2017 12:02:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1coU5T-0003iM-Sn for pgsql-hackers@postgresql.org; Thu, 16 Mar 2017 12:00:59 +0000 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1coU5R-0004I3-H5 for pgsql-hackers@postgresql.org; Thu, 16 Mar 2017 12:00:59 +0000 Received: by mail-wr0-x22a.google.com with SMTP id l37so30381830wrc.1 for ; Thu, 16 Mar 2017 05:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=ijyCODbCcEC5MZw1xAKiJ7yDhX0n6L4WzwsSwkE/2dQ=; b=LFsaBe+qarFfwA1yY8dEEtQVAme3WODRahQCTRUVZjPO1nFXsewafChaLK5gs5gM4a pV4qvNfA5aLYRog7DkKMKWCbIwa5PZOXVHsmHGkdgiPuMxpV7LOhejaeRcxpoDnbkzVe ffuvGfKiFM7cdg0NFDu51ZDG33bg59xAfFf/op3h/ecg2sGj3BJfzZAB95naExmMKEb4 GsZa+yIYOjntCqfrXFTZasstqLF6Bxk6BzlY+EX6XQXHKANSRKtxZ80+9kpLYxxLI9Tn 3B5Y0giKGjhzb5NMnulEIIvwDtZLuej5bICv7DDFDzdRZefRMJMlL5FgG9LL3CjdI3RS TwHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=ijyCODbCcEC5MZw1xAKiJ7yDhX0n6L4WzwsSwkE/2dQ=; b=cRy3AHeNd4Rk4NOg/pNBzTAND50eNEv2QwuM0+3jsmuwtc/d1cjTShWBJn6Zc/gQrw DkjQS0s4xOVeMyEC5JGPEHk/8zwF+0qObP5kAeqf9OVuLK/uDdt8EaOytf+/193aofQB 49u+3s2ra7tkCmGTvups42X4EhTc1xWAOph919QS7tvOHYzf/gu+qAg/FyHjsEf0XU4i AQzhJ43QF+lUvKJzugqLkCv2I4wzFtVJtcfMWPYRVoeImloUiKzKNcSGeemzFCnDR0f+ Ts4/X+YZGvWWeeMt/cx5Dg4MKCbppUSKqZqAUG/LIQXAMUUuN2H2R8xPbzMmUsdPLmaM VWwg== X-Gm-Message-State: AFeK/H0Bvp0kJe/4aroTgWZ1vSxfSj89xoVXy2zH/zWcvQ10Zu2nlAQW/P6qMDPm7jqx0XBKBNTTo0xtcKk/eInqrMEVvfszKJJ7E8Bi045VEiScYfDQZBCDJaXO1njL7AbF97BEjrEBtrKq30m1Y507W1ISlEovz+321XJdv9szrd2+EqZuKgAwxyjnqBXmoDYMNtdpGL45 X-Received: by 10.223.139.5 with SMTP id n5mr7809136wra.200.1489665656256; Thu, 16 Mar 2017 05:00:56 -0700 (PDT) Received: from [192.168.0.105] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id q12sm4078475wmd.8.2017.03.16.05.00.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Mar 2017 05:00:55 -0700 (PDT) Subject: Re: [COMMITTERS] pgsql: Use asynchronous connect API in libpqwalreceiver To: Tom Lane , Andrew Dunstan References: <19403.1488586564@sss.pgh.pa.us> <34d98fbf-9195-04d2-b85a-634d6952ffdf@2ndquadrant.com> <19815.1488600693@sss.pgh.pa.us> <091deea0-75f2-cfda-ee8c-424162852084@2ndQuadrant.com> <7295.1489596949@sss.pgh.pa.us> Cc: Peter Eisentraut , pgsql-hackers@postgreSQL.org From: Petr Jelinek Message-ID: <5eff6c57-eaca-c721-339b-3b621d87ce75@2ndquadrant.com> Date: Thu, 16 Mar 2017 13:00:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <7295.1489596949@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 15/03/17 17:55, Tom Lane wrote: > Andrew Dunstan writes: >> On 03/03/2017 11:11 PM, Tom Lane wrote: >>> Yeah, I was wondering if this is just exposing a pre-existing bug. >>> However, the "normal" path operates by repeatedly invoking PQconnectPoll >>> (cf. connectDBComplete) so it's not immediately obvious how such a bug >>> would've escaped detection. > >> (After a long period of fruitless empirical testing I turned to the code) >> Maybe I'm missing something, but connectDBComplete() handles a return of >> PGRESS_POLLING_OK as a success while connectDBStart() seems not to. I >> don't find anywhere in our code other than libpqwalreceiver that >> actually uses that interface, so it's not surprising if it's now >> failing. So my bet is it is indeed a long-standing bug. > > Meh ... that argument doesn't hold water, because the old code here called > PQconnectdbParams which is just PQconnectStartParams then > connectDBComplete. So the problem cannot be in connectDBStart; that's > common to both paths. It has to be some discrepancy between what > connectDBComplete does and what the new loop in libpqwalreceiver is doing. > > The original loop coding in 1e8a85009 was not very close to the documented > spec for PQconnectPoll at all, and while e434ad39a made it closer, it's > still not really the same: connectDBComplete doesn't call PQconnectPoll > until the socket is known read-ready or write-ready. The walreceiver loop > does not guarantee that, but would make an additional call after any > random other wakeup. It's not very clear why bowerbird, and only > bowerbird, would be seeing such wakeups --- but I'm having a really hard > time seeing any other explanation for the change in behavior. (I wonder > whether bowerbird is telling us that WaitLatchOrSocket can sometimes > return prematurely on Windows.) > > I'm also pretty sure that the ResetLatch call is in the wrong place which > could lead to missed wakeups, though that's the opposite of the immediate > problem. > > I'll try correcting these things and we'll see if it gets any better. > Looks like that didn't help either. I setup my own Windows machine and can reproduce the issue. I played around a bit and could not really find a fix other than adding WL_TIMEOUT and short timeout to WaitLatchOrSocket (it does wait a very long time on the WaitLatchOrSocket otherwise before failing). So I wonder if this is the same issue that caused us using different coding for WaitLatchOrSocket in pgstat.c (lines ~3918-3940). -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers