diff options
author | Tatsuo Ishii | 2024-09-18 02:25:10 +0000 |
---|---|---|
committer | Tatsuo Ishii | 2024-09-18 02:33:38 +0000 |
commit | 4ac2f8801508922ef75c5f476b8edae988f635c1 (patch) | |
tree | d7e4d18dae254e6db49f7525eb7cbdd141211169 | |
parent | b9b2b6edfb7a1b215c2a52b3db90695b6258145f (diff) |
Fix pgpool crash when pgpool child process exits.
When a pgpool child process exits, close_all_backend_connections() is
called, which is responsible for closing all connections to backend in
the connection pool. It used mistakenly MAIN_CONNECTION macro, which
is fine for current active connections but is not good for pooled
connections because a main node could be different at the time when
the connection pool was created. Fix is using in_use_backend()
instead.
Reported-by: Emond Papegaaij
Backpatch-through: v4.2
-rw-r--r-- | src/protocol/pool_connection_pool.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/protocol/pool_connection_pool.c b/src/protocol/pool_connection_pool.c index 79ee7e786..d7e1857a4 100644 --- a/src/protocol/pool_connection_pool.c +++ b/src/protocol/pool_connection_pool.c @@ -1073,11 +1073,15 @@ close_all_backend_connections(void) for (i = 0; i < pool_config->max_pool; i++, p++) { - if (!MAIN_CONNECTION(p)) + int backend_id = in_use_backend_id(p); + + if (backend_id < 0) continue; - if (!MAIN_CONNECTION(p)->sp) + if (CONNECTION_SLOT(p, backend_id) == NULL) continue; - if (MAIN_CONNECTION(p)->sp->user == NULL) + if (CONNECTION_SLOT(p, backend_id)->sp == NULL) + continue; + if (CONNECTION_SLOT(p, backend_id)->sp->user == NULL) continue; pool_send_frontend_exits(p); } |