Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rjxpJ-009HIr-RT for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 08:49:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rjxpI-008c59-34 for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 08:49:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rjxpH-008c50-Px for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2024 08:49:36 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rjxpF-00459s-D0 for pgsql-hackers@postgresql.org; Tue, 12 Mar 2024 08:49:35 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4Tv6lJ3KKxzyV6 for ; Tue, 12 Mar 2024 10:49:31 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1710233372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c1kqC8IgXRxg9ggfS6oXzBuydi9ZKWrfA3IbSjujIOw=; b=x2sR/lWDfSEfMAXHZJZN4ZBB3Or4x7WITCKdZbV+Rkwy0G+YwxfFA4/ZB/jNdIKZiu4iAq WTnVBicySHxHFysb2tB9AhhTbf31jMz6J3okJfd2c3EnepgN+rMxq/ZX1+5RB1gXI+Sy5N Zkfw+Wb1qnKpgW2hMNg6ZB2XxQgHvYo= ARC-Seal: i=1; s=meesny; d=iki.fi; t=1710233372; a=rsa-sha256; cv=none; b=P3rjBvS/tTPee2/r6pnScxr5szFEbH9P5W/srIqv+aU4vOiNKef5oekEdsWppnMd7lNmkb DcS5sZgGiufx8KYIZjg+2UILEMmAiBZMIRD9ojJTzrXmLfiikncFAAqHpdmXpxvvm+CqHm 7YfDvaH1EYdiGpHsTOcYxANyk15k5TY= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1710233372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c1kqC8IgXRxg9ggfS6oXzBuydi9ZKWrfA3IbSjujIOw=; b=tdZfSV5St0tn8q/1n8voFDI3EuUaIJKr5sVBvQqn36yFhXwFGpTwrVACIaLq/DM5bZVlQG 9rExwiuri2daYgIY45ra0bsUZXQOUOttuCXZX6E8LcxiyAWa6/drQyES6Y3K1GbdsNWCI5 4Jl5QqrouUfBWxKxR3Zay3d556qfdqI= Message-ID: <5f600c8b-19f2-4cc7-9e9f-65130117223f@iki.fi> Date: Tue, 12 Mar 2024 10:49:31 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Disconnect if socket cannot be put into non-blocking mode Content-Language: en-US From: Heikki Linnakangas To: pgsql-hackers References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/03/2024 16:44, Heikki Linnakangas wrote: > While self-reviewing my "Refactoring backend fork+exec code" patches, I > noticed this in pq_init(): > >> /* >> * In backends (as soon as forked) we operate the underlying socket in >> * nonblocking mode and use latches to implement blocking semantics if >> * needed. That allows us to provide safely interruptible reads and >> * writes. >> * >> * Use COMMERROR on failure, because ERROR would try to send the error to >> * the client, which might require changing the mode again, leading to >> * infinite recursion. >> */ >> #ifndef WIN32 >> if (!pg_set_noblock(MyProcPort->sock)) >> ereport(COMMERROR, >> (errmsg("could not set socket to nonblocking mode: %m"))); >> #endif >> >> #ifndef WIN32 >> >> /* Don't give the socket to any subprograms we execute. */ >> if (fcntl(MyProcPort->sock, F_SETFD, FD_CLOEXEC) < 0) >> elog(FATAL, "fcntl(F_SETFD) failed on socket: %m"); >> #endif > > Using COMMERROR here seems bogus. Firstly, if there was a problem with > recursion, surely the elog(FATAL) that follows would also be wrong. But > more seriously, it's not cool to continue using the connection as if > everything is OK, if we fail to put it into non-blocking mode. We should > disconnect. (COMMERROR merely logs the error, it does not bail out like > ERROR does) > > Barring objections, I'll commit and backpatch the attached to fix that. Committed. -- Heikki Linnakangas Neon (https://neon.tech)