@@ -911,7 +911,6 @@ pg_stop_backup(pgBackup *backup)
911
911
XLogRecPtr restore_lsn ;
912
912
bool sent = false;
913
913
int pg_stop_backup_timeout = 0 ;
914
- int is_busy = 1 ;
915
914
916
915
/*
917
916
* We will use this values if there are no transactions between start_lsn
@@ -1035,37 +1034,37 @@ pg_stop_backup(pgBackup *backup)
1035
1034
* but no longer than PG_STOP_BACKUP_TIMEOUT seconds
1036
1035
*/
1037
1036
elog (INFO , "wait for pg_stop_backup()" );
1038
- do
1037
+
1038
+ while (1 )
1039
1039
{
1040
- /*
1041
- * PQisBusy returns 1 if a command is busy, that is, PQgetResult would
1042
- * block waiting for input. A 0 return indicates that PQgetResult can
1043
- * be called with assurance of not blocking
1044
- */
1045
- is_busy = PQisBusy (backup_conn );
1046
- pg_stop_backup_timeout ++ ;
1047
- sleep (1 );
1040
+ if (!PQconsumeInput (backup_conn ) || PQisBusy (backup_conn ))
1041
+ {
1042
+ pg_stop_backup_timeout ++ ;
1043
+ sleep (1 );
1048
1044
1049
- if (interrupted )
1045
+ if (interrupted )
1046
+ {
1047
+ pgut_cancel (backup_conn );
1048
+ elog (ERROR , "interrupted during waiting for pg_stop_backup" );
1049
+ }
1050
+ /*
1051
+ * If postgres haven't answered in PG_STOP_BACKUP_TIMEOUT seconds,
1052
+ * send an interrupt.
1053
+ */
1054
+ if (pg_stop_backup_timeout > PG_STOP_BACKUP_TIMEOUT )
1055
+ {
1056
+ pgut_cancel (backup_conn );
1057
+ elog (ERROR , "pg_stop_backup doesn't answer in %d seconds, cancel it" ,
1058
+ PG_STOP_BACKUP_TIMEOUT );
1059
+ }
1060
+ }
1061
+ else
1050
1062
{
1051
- pgut_cancel (backup_conn );
1052
- elog ( ERROR , "interrupted during waiting for pg_stop_backup" ) ;
1063
+ res = PQgetResult (backup_conn );
1064
+ break ;
1053
1065
}
1054
-
1055
- } while (is_busy && pg_stop_backup_timeout < PG_STOP_BACKUP_TIMEOUT );
1056
-
1057
- /*
1058
- * If postgres haven't answered in PG_STOP_BACKUP_TIMEOUT seconds,
1059
- * send an interrupt.
1060
- */
1061
- if (is_busy )
1062
- {
1063
- pgut_cancel (backup_conn );
1064
- elog (ERROR , "pg_stop_backup doesn't finish in 300 seconds." );
1065
1066
}
1066
1067
1067
- res = PQgetResult (backup_conn );
1068
-
1069
1068
if (!res )
1070
1069
elog (ERROR , "pg_stop backup() failed" );
1071
1070
0 commit comments