Skip to content

Commit f8c5317

Browse files
committed
Disconnect if socket cannot be put into non-blocking mode
Commit 387da18 moved the code to put socket into non-blocking mode from socket_set_nonblocking() into the one-time initialization function, pq_init(). In socket_set_nonblocking(), there indeed was a risk of recursion on failure like the comment said, but in pq_init(), ERROR or FATAL is fine. There's even another elog(FATAL) just after this, if setting FD_CLOEXEC fails. Note that COMMERROR merely logged the error, it did not close the connection, so if putting the socket to non-blocking mode failed we would use the connection anyway. You might not immediately notice, because most socket operations in a regular backend wait for the socket to become readable/writable anyway. But e.g. replication will be quite broken. Backpatch to all supported versions. Discussion: https://www.postgresql.org/message-id/d40a5cd0-2722-40c5-8755-12e9e811fa3c@iki.fi
1 parent 4dec98c commit f8c5317

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/backend/libpq/pqcomm.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,10 @@ pq_init(void)
189189
* nonblocking mode and use latches to implement blocking semantics if
190190
* needed. That allows us to provide safely interruptible reads and
191191
* writes.
192-
*
193-
* Use COMMERROR on failure, because ERROR would try to send the error to
194-
* the client, which might require changing the mode again, leading to
195-
* infinite recursion.
196192
*/
197193
#ifndef WIN32
198194
if (!pg_set_noblock(MyProcPort->sock))
199-
ereport(COMMERROR,
195+
ereport(FATAL,
200196
(errmsg("could not set socket to nonblocking mode: %m")));
201197
#endif
202198

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy