mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 00:26:30 +00:00
Add a check of the connection inside the CancelQuery() so it check
that before trying to cancel a query, which can block.
This commit is contained in:
@@ -146,7 +146,7 @@ is_pgup(PGconn *conn, int timeout)
|
|||||||
/*
|
/*
|
||||||
* Send a SELECT 1 just to check if the connection is OK
|
* Send a SELECT 1 just to check if the connection is OK
|
||||||
*/
|
*/
|
||||||
CancelQuery(conn);
|
CancelQuery(conn, timeout);
|
||||||
if (wait_connection_availability(conn, timeout) != 1)
|
if (wait_connection_availability(conn, timeout) != 1)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
@@ -430,11 +430,13 @@ wait_connection_availability(PGconn *conn, int timeout)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CancelQuery(PGconn *conn)
|
CancelQuery(PGconn *conn, int timeout)
|
||||||
{
|
{
|
||||||
char errbuf[ERRBUFF_SIZE];
|
char errbuf[ERRBUFF_SIZE];
|
||||||
PGcancel *pgcancel;
|
PGcancel *pgcancel;
|
||||||
|
|
||||||
|
wait_connection_availability(conn, timeout);
|
||||||
|
|
||||||
pgcancel = PQgetCancel(conn);
|
pgcancel = PQgetCancel(conn);
|
||||||
|
|
||||||
if (!pgcancel || PQcancel(pgcancel, errbuf, ERRBUFF_SIZE) == 0)
|
if (!pgcancel || PQcancel(pgcancel, errbuf, ERRBUFF_SIZE) == 0)
|
||||||
@@ -442,5 +444,3 @@ CancelQuery(PGconn *conn)
|
|||||||
|
|
||||||
PQfreeCancel(pgcancel);
|
PQfreeCancel(pgcancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,5 +37,5 @@ PGconn *getMasterConnection(PGconn *standby_conn, char *schema, char *cluster,
|
|||||||
int *master_id, char *master_conninfo_out);
|
int *master_id, char *master_conninfo_out);
|
||||||
|
|
||||||
int wait_connection_availability(PGconn *conn, int timeout);
|
int wait_connection_availability(PGconn *conn, int timeout);
|
||||||
void CancelQuery(PGconn *conn);
|
void CancelQuery(PGconn *conn, int timeout);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ static void setup_event_handlers(void);
|
|||||||
|
|
||||||
#define CloseConnections() \
|
#define CloseConnections() \
|
||||||
if (PQisBusy(primaryConn) == 1) \
|
if (PQisBusy(primaryConn) == 1) \
|
||||||
CancelQuery(primaryConn); \
|
CancelQuery(primaryConn, local_options.master_response_timeout); \
|
||||||
if (myLocalConn != NULL) \
|
if (myLocalConn != NULL) \
|
||||||
PQfinish(myLocalConn); \
|
PQfinish(myLocalConn); \
|
||||||
if (primaryConn != NULL && primaryConn != myLocalConn) \
|
if (primaryConn != NULL && primaryConn != myLocalConn) \
|
||||||
@@ -356,7 +356,7 @@ WitnessMonitor(void)
|
|||||||
* Cancel any query that is still being executed,
|
* Cancel any query that is still being executed,
|
||||||
* so i can insert the current record
|
* so i can insert the current record
|
||||||
*/
|
*/
|
||||||
CancelQuery(primaryConn);
|
CancelQuery(primaryConn, local_options.master_response_timeout);
|
||||||
if (wait_connection_availability(primaryConn, local_options.master_response_timeout) != 1)
|
if (wait_connection_availability(primaryConn, local_options.master_response_timeout) != 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -473,7 +473,7 @@ StandbyMonitor(void)
|
|||||||
* Cancel any query that is still being executed,
|
* Cancel any query that is still being executed,
|
||||||
* so i can insert the current record
|
* so i can insert the current record
|
||||||
*/
|
*/
|
||||||
CancelQuery(primaryConn);
|
CancelQuery(primaryConn, local_options.master_response_timeout);
|
||||||
if (wait_connection_availability(primaryConn, local_options.master_response_timeout) != 1)
|
if (wait_connection_availability(primaryConn, local_options.master_response_timeout) != 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user