Skip to content

Commit

Permalink
Fix Pgpool-II child process crash during shutdown.
Browse files Browse the repository at this point in the history
It is reported that pgpool child process crashes during shutdown.
[pgpool-general: 9261] Re: Segmentation fault during shutdown

The actual crash was in close_all_backend_connections().
close_all_backend_connections() was called because on_system_exit
registers child_will_go_down(). At the moment it seems pgpool child
had just started up and doing pool_init_cp(). The connection pool
object had not been completely initialized, that's cause of the crash.

To fix this, introduce a new static variable in child.c and set it
true when the connection pool object is initialized. In
child_will_go_down() it is checked and close_all_backend_connections()
is called only when the variable is set to true.

Problem reported and analyzed by: Emond Papegaaij
Backpatch-through: v4.2
Discussion: https://www.pgpool.net/pipermail/pgpool-general/2024-November/001938.html
  • Loading branch information
tatsuo-ishii committed Nov 9, 2024
1 parent af21a22 commit a690ce0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/protocol/child.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ struct timeval startTime;
bool stop_now = false;
#endif

/*
* If true, connection pool has been initialized.
*/
static bool connection_pool_initialized = false;

/*
* child main loop
*/
Expand Down Expand Up @@ -223,6 +228,7 @@ do_child(int *fds)
{
child_exit(POOL_EXIT_AND_RESTART);
}
connection_pool_initialized = true;

/*
* Open pool_passwd in child process. This is necessary to avoid the file
Expand Down Expand Up @@ -1308,7 +1314,7 @@ child_will_go_down(int code, Datum arg)
}

/* let backend know now we are exiting */
if (pool_connection_pool)
if (connection_pool_initialized)
close_all_backend_connections();
}
void
Expand Down

0 comments on commit a690ce0

Please sign in to comment.