Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit fa73c8e

Browse files
committed
Safeguard cancel_backup loops with timeouts to prevent infinite hangs
1 parent 49066f1 commit fa73c8e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

samples/samples/archived/backup_snippet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def cancel_backup(instance_id, database_id, backup_id):
4141

4242
# Cancel operations are best effort so either it will complete or
4343
# be cancelled.
44-
while not operation.done():
44+
timeout_at = time.time() + 600 # 10 minutes max wait
45+
while not operation.done() and time.time() < timeout_at:
4546
time.sleep(300) # 5 mins
4647

4748
# Deal with resource if the operation succeeded.

samples/samples/backup_sample.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ def cancel_backup(instance_id, database_id, backup_id):
322322

323323
# Cancel operations are the best effort so either it will complete or
324324
# be cancelled.
325-
while not operation.done():
325+
timeout_at = time.time() + 600 # 10 minutes max wait
326+
while not operation.done() and time.time() < timeout_at:
326327
time.sleep(300) # 5 mins
327328

328329
try:

0 commit comments

Comments
 (0)