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 1mLSV7-0005R2-CE for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Sep 2021 15:50:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mLSV6-00042x-6R for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Sep 2021 15:50:08 +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 1mLSV5-00042o-Ux for pgsql-hackers@lists.postgresql.org; Wed, 01 Sep 2021 15:50:07 +0000 Received: from aldebaran.he1ix.org ([2a01:4f8:173:803:0:a1de:ba:a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLSV0-0007IJ-V1 for pgsql-hackers@lists.postgresql.org; Wed, 01 Sep 2021 15:50:06 +0000 Received: from port-213-160-25-97.static.as20676.net ([213.160.25.97] helo=[192.168.33.110]) by aldebaran.he1ix.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1mLSUw-005RM5-2Q; Wed, 01 Sep 2021 17:49:58 +0200 To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org References: <48bafc63-c30f-3962-2ded-f2e985d93e86@emmenlauer.de> <3ac84ee7-b4a0-aba5-ddb5-b7c0811fc754@emmenlauer.de> <1c4c2254-1812-2913-8630-18d4b9262a89@emmenlauer.de> <2071112.1630504486@sss.pgh.pa.us> From: Mario Emmenlauer Message-ID: Date: Wed, 1 Sep 2021 17:49:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <2071112.1630504486@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 213.160.25.97 X-SA-Exim-Mail-From: mario@emmenlauer.de X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on aldebaran.he1ix.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.4 Subject: Re: dup(0) fails on Ubuntu 20.04 and macOS 10.15 with 13.0 X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on aldebaran.he1ix.org) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 01.09.21 15:54, Tom Lane wrote: > 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 successes: 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. > >> 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. > > 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. The idea to switch to dup(2) sounds very good to me. Also, while at it, maybe the error message could be improved? The kids nowadays don't learn so much about system I/O any more, and if someone does not know `dup()`, then the error message is not very telling. It took me a while to under- stand what the code was supposed to do. So it may be helpful to add to the error message something like "possible the stderr stream is closed, this is not supported". What do you think? All the best, Mario Emmenlauer