Fix segfault to not use MAIN_NODE macro.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 21 Jun 2024 06:37:25 +0000 (15:37 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 21 Jun 2024 06:56:51 +0000 (15:56 +0900)
commit8f292aaf88ce31061b49aea2aca8ce561640eb05
treeb597c605c83d42059337416462696a497d4f41c4
parent0690a4f12ab1aeba4b970bb5415eafdecef78273
Fix segfault to not use MAIN_NODE macro.

Some functions (close_idle_connection(), new_connection() and
pool_create_cp()) used MAIN* and VALID_BACKEND where they are not
appropriate. MAIN* and VALID_BACKEND are only useful against current
connections to backend, not for pooled connections since in pooled
connections which backend is the main node or up and running is
necessarily same as the current connections to backend.
The misuses of those macros sometimes leads to segfault.

This patch introduces new in_use_backend_id() which returns the fist
node id in use. This commit replaces some of MAIN* with the return
value from in_use_backend_id(). Also inappropriate calls to
VALID_BACKEND are replaced with CONNECTION_SLOT macro.

Problem reported by Emond Papegaaij
Discussion: https://www.pgpool.net/pipermail/pgpool-general/2024-June/009176.html
[pgpool-general: 9114] Re: Another segmentation fault
Backpatch-through: V4.1
src/include/protocol/pool_connection_pool.h
src/protocol/child.c
src/protocol/pool_connection_pool.c