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 1mLQhb-0001NA-LN for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Sep 2021 13:54:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mLQhZ-0000rS-Qc for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Sep 2021 13:54:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLQhZ-0000nu-IV for pgsql-hackers@lists.postgresql.org; Wed, 01 Sep 2021 13:54:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLQhX-0006R9-LZ for pgsql-hackers@lists.postgresql.org; Wed, 01 Sep 2021 13:54:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 181DskdV2071113; Wed, 1 Sep 2021 09:54:48 -0400 From: Tom Lane To: Mario Emmenlauer cc: pgsql-hackers@lists.postgresql.org Subject: Re: dup(0) fails on Ubuntu 20.04 and macOS 10.15 with 13.0 In-reply-to: <1c4c2254-1812-2913-8630-18d4b9262a89@emmenlauer.de> References: <48bafc63-c30f-3962-2ded-f2e985d93e86@emmenlauer.de> <3ac84ee7-b4a0-aba5-ddb5-b7c0811fc754@emmenlauer.de> <1c4c2254-1812-2913-8630-18d4b9262a89@emmenlauer.de> Comments: In-reply-to Mario Emmenlauer message dated "Wed, 01 Sep 2021 10:55:23 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2071111.1630504486.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 01 Sep 2021 09:54:46 -0400 Message-ID: <2071112.1630504486@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk [ redirecting to -hackers ] Mario Emmenlauer writes: > On 05.10.20 14:35, Tom Lane wrote: >> Mario Emmenlauer writes: >>> I get reproducibly the error: >>> 2020-10-05 11:48:19.720 CEST [84731] WARNING: dup(0) failed after 0 s= uccesses: Bad file descriptor >> Hmph. That code loop assumes that stdin exists to be duplicated, >> but maybe if it had been closed, you'd get this error. >> = >> However, that logic hasn't changed in decades, and we've not heard >> complaints about it before. Are you starting the server in some >> unusual way? > Replying to a very old thread here: I could indeed trace the problem of > the failing `dup(0)` back to how we start the server! We start the > server from an executable that closes stdin very early on, and this > seems to lead to the problem. > We solved it by not closing stdin. But for future reference, if other > people may be affected by this, the code could probably be modified to > revert to stdout or stderr or a temporary file in case stdin is not > available (guessing here...). Hm. I'm tempted to propose that we simply change that from dup(0) to dup(2). Formally, that's just moving the problem around. In practice though, there are good reasons not to close the server's stderr, ie you will lose error messages that might be important. OTOH there does not seem to be any obvious reason why the server should need valid stdin, so if we can get rid of an implementation artifact that makes it require that, that seems like an improvement. regards, tom lane