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:37:25 +0000 (15:37 +0900)
commit98fff9832f602ea5571427982f1050348f9f0219
tree74db682ff8e64c6c6700f32bc1a42b2b33517359
parentd699b8f129c70f434c525208b58bcc09da36f3a3
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