pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode

Commit 387da18874 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-12e9e811f...@iki.fi

Branch
--
REL_13_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/ad5cd55e675c6b55a521d9db5e57bba5a02a9208

Modified Files
--
src/backend/libpq/pqcomm.c | 6 +-
1 file changed, 1 insertion(+), 5 deletions(-)



pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode

Commit 387da18874 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-12e9e811f...@iki.fi

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/f8c5317d001556a51441fad81e8f6c32994f2d79

Modified Files
--
src/backend/libpq/pqcomm.c | 6 +-
1 file changed, 1 insertion(+), 5 deletions(-)



pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode

Commit 387da18874 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-12e9e811f...@iki.fi

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/539e328b1c3a4047c7ff525524edbcca2bac6e10

Modified Files
--
src/backend/libpq/pqcomm.c | 6 +-
1 file changed, 1 insertion(+), 5 deletions(-)



pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode

Commit 387da18874 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-12e9e811f...@iki.fi

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/bf1f593e899ee9aa1de80164a3005b02474deb50

Modified Files
--
src/backend/libpq/pqcomm.c | 6 +-
1 file changed, 1 insertion(+), 5 deletions(-)



pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode

Commit 387da18874 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-12e9e811f...@iki.fi

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/4fce5f970d584114ba9f981b367eb7720621cc50

Modified Files
--
src/backend/libpq/pqcomm.c | 6 +-
1 file changed, 1 insertion(+), 5 deletions(-)



pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode

Commit 387da18874 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-12e9e811f...@iki.fi

Branch
--
REL_12_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/df27d76d32f2c1a2572983a5c6a874d003cd0321

Modified Files
--
src/backend/libpq/pqcomm.c | 6 +-
1 file changed, 1 insertion(+), 5 deletions(-)