Skip to content

Commit

Permalink
repmgrd: ensure potentially open connections are closed
Browse files Browse the repository at this point in the history
When recovering from degraded state in local node monitoring, in some
cases a new connection was opened to the local node without closing
the old one, which will result in memory leakage.
  • Loading branch information
zhouhj43183 authored and ibarwick committed Jan 4, 2022
1 parent 81f9c0e commit 2dce8e1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion repmgrd-physical.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ monitor_streaming_primary(void)

if (is_server_available(local_node_info.conninfo) == true)
{
close_connection(&local_conn);
local_conn = establish_db_connection(local_node_info.conninfo, false);

if (PQstatus(local_conn) != CONNECTION_OK)
Expand Down Expand Up @@ -1813,7 +1814,10 @@ monitor_streaming_standby(void)
if (upstream_check_result == true)
{
if (config_file_options.connection_check_type != CHECK_QUERY)
{
close_connection(&upstream_conn);
upstream_conn = establish_db_connection(upstream_node_info.conninfo, false);
}

if (PQstatus(upstream_conn) == CONNECTION_OK)
{
Expand Down Expand Up @@ -2546,8 +2550,10 @@ monitor_streaming_witness(void)
if (check_upstream_connection(&primary_conn, upstream_node_info.conninfo, NULL) == true)
{
if (config_file_options.connection_check_type != CHECK_QUERY)
{
close_connection(&primary_conn);
primary_conn = establish_db_connection(upstream_node_info.conninfo, false);

}
if (PQstatus(primary_conn) == CONNECTION_OK)
{
PQExpBufferData event_details;
Expand Down

0 comments on commit 2dce8e1

Please sign in to comment.