Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pAwcz-0001tV-5h for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Dec 2022 17:23:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pAwcy-0004f3-43 for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Dec 2022 17:23:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pAwcx-0004eu-RB for pgsql-hackers@lists.postgresql.org; Thu, 29 Dec 2022 17:23:35 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pAwcv-0004wz-C5 for pgsql-hackers@postgresql.org; Thu, 29 Dec 2022 17:23:35 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 5708B5C00D1; Thu, 29 Dec 2022 12:23:32 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 29 Dec 2022 12:23:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1672334612; x=1672421012; bh=IaOadwV12q ZlxRsvDYqF8Ar0o49kpcTNnCOpi2jiftc=; b=WMeJTkfh6uFjxZLkH6nM+mJU14 dGetGMbV+m5rEq3uXkIRNPqP6flbGDzgX1yqVbkn8C32nNo3Ha9WWWZDSReT+YKh dmZ5XcMBDV84leSVC7JrxR+13NAib0dKhR32vrYbeEF45OfrbD8RjiIeW4qbNjPc yAp0fZmS2cqTDPScr8wCouYnZLveaqazYTzLnypxVqiHkXmHgZj1fm2VQWxqK4rg BoFEMulbFw6kVg3Ag23dRO3I36+PbNGoyig36lSu+Q8LO86Akv5yxCmI0SsJkmOT bKCyg92S8rNMcmIPIlTph96sT6adxzfL/qzOv6ijW1xuZMDUofRKqQXHY3Xw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1672334612; x=1672421012; bh=IaOadwV12qZlxRsvDYqF8Ar0o49k pcTNnCOpi2jiftc=; b=vLdyC0LfzNXUUMulVk5fXczCrQ1egFFGex1101P2kVbb AhrmqsdceBPRvux+GNt+d7l9MvRouoJ91yXpZnto8b6TBjBCVFjTYXs7NW+HHXrj USK7GxzEipoMgzKFmHz9BbiFUtN4FnFgVpkeYtlWFQUxkGjl0LyAOa62Ds5sL9ZW I+PFxYQyRE3BjHsT6TlMd55IGeBjkMIrruuQHFG+m3JIUkDHRt92OZv646Zdat06 33Twn/uREEbKrX/ZWQWMShpYhNAOh6qhCYJQbGgUtvhT2oh64idcb4Ec/rM5QqsD pT0R9aP+u15ylk14+ysAhdp+fbEDjKGnhyxbVJDocQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieeggddutdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpeetheehiefgudelhfevvddvtdejheehkeelteekveeggeduieelieduuefg fedtjeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgr iigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 12:23:31 -0500 (EST) Date: Thu, 29 Dec 2022 09:23:30 -0800 From: Andres Freund To: pgsql-hackers@postgresql.org, Thomas Munro , Robert Haas , Peter Geoghegan , Tom Lane Subject: Re: postgres_fdw uninterruptible during connection establishment / ProcSignalBarrier Message-ID: <20221229172330.jpuoljhtvivci3cd@awork3.anarazel.de> References: <20220925232237.p6uskba2dw6fnwj2@awork3.anarazel.de> <20221209020815.wsoixct72c6hst5l@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221209020815.wsoixct72c6hst5l@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2022-12-08 18:08:15 -0800, Andres Freund wrote: > I just re-discovered this issue, via > https://www.postgresql.org/message-id/20221209003607.bz2zdznvfnkq4zz3%40awork3.anarazel.de > > > On 2022-09-25 16:22:37 -0700, Andres Freund wrote: > > Maybe I am missing something, but I don't think it's OK for > > connect_pg_server() to connect in a blocking manner, without accepting > > interrupts? > > It's definitely not. This basically means network issues or such can lead to > connections being unkillable... > > We know how to do better, c.f. libpqrcv_connect(). I hacked that up for > postgres_fdw, and got through quite a few runs without related issues ([1]). > > The same problem is present in two places in dblink.c. Obviously we can copy > and paste the code to dblink.c as well. But that means we have the same not > quite trivial code in three different c files. There's already a fair bit of > duplicated code around AcquireExternalFD(). > > It seems we should find a place to put backend specific libpq wrapper code > somewhere. Unless we want to relax the rule about not linking libpq into the > backend we can't just put it in the backend directly, though. > > The only alternative way to provide a wrapper that I can think of are to > a) introduce a new static library that can be linked to by libpqwalreceiver, > postgres_fdw, dblink > b) add a header with static inline functions implementing interrupt-processing > connection establishment for libpq > > Neither really has precedent. > > The attached quick patch just adds and uses libpq_connect_interruptible() in > postgres_fdw. If we wanted to move this somewhere generic, at least part of > the external FD handling should also be moved into it. > > > dblink.c uses a lot of other blocking libpq functions, which obviously also > isn't ok. > > > Perhaps we could somehow make this easier from within libpq? My first thought > was a connection parameter that'd provide a different implementation of > pqSocketCheck() or such - but I don't think that'd work, because we might > throw errors when processing interrupts, and that'd not be ok from deep within > libpq. Any opinions? Due to the simplicity I'm currently leaning to a header-only helper, but I don't feel confident about it. The rate of cfbot failures is high enough that it'd be good to do something about this. Greetings, Andres Freund