@@ -911,7 +911,6 @@ pg_stop_backup(pgBackup *backup)
911911XLogRecPtr restore_lsn ;
912912bool sent = false;
913913int pg_stop_backup_timeout = 0 ;
914- int is_busy = 1 ;
915914
916915/*
917916 * We will use this values if there are no transactions between start_lsn
@@ -1035,37 +1034,37 @@ pg_stop_backup(pgBackup *backup)
10351034 * but no longer than PG_STOP_BACKUP_TIMEOUT seconds
10361035 */
10371036elog (INFO ,"wait for pg_stop_backup()" );
1038- do
1037+
1038+ while (1 )
10391039{
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 );
10481044
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
10501062{
1051- pgut_cancel (backup_conn );
1052- elog ( ERROR , "interrupted during waiting for pg_stop_backup" ) ;
1063+ res = PQgetResult (backup_conn );
1064+ break ;
10531065}
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." );
10651066}
10661067
1067- res = PQgetResult (backup_conn );
1068-
10691068if (!res )
10701069elog (ERROR ,"pg_stop backup() failed" );
10711070