Skip to content

Commit

Permalink
Fix pgpool crash when pgpool child process exits.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tatsuo-ishii committed Sep 18, 2024
1 parent b9b2b6e commit 4ac2f88
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/protocol/pool_connection_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4ac2f88

Please sign in to comment.