From cf69dc7f24f6183e3ba3cef594a916db29b846e9 Mon Sep 17 00:00:00 2001 From: ramo-j Date: Mon, 17 Nov 2025 23:49:21 +0000 Subject: [PATCH] Added exponential backoff to snapshot creation throttling errors --- libcloudforensics/providers/gcp/forensics.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libcloudforensics/providers/gcp/forensics.py b/libcloudforensics/providers/gcp/forensics.py index 5d06e712..237e7c64 100644 --- a/libcloudforensics/providers/gcp/forensics.py +++ b/libcloudforensics/providers/gcp/forensics.py @@ -18,6 +18,7 @@ import random import re import subprocess +import time from typing import List, Tuple, Optional, Dict, Any, Union, Sequence from google.auth.exceptions import DefaultCredentialsError @@ -90,7 +91,22 @@ def CreateDiskCopy( disk_type = 'pd-standard' logger.info('Disk copy of {0:s} started...'.format(disk_to_copy.name)) - snapshot, created = disk_to_copy.Snapshot() + + attempts = 0 + max_attempts = 5 + backoff = 1 + while attempts < max_attempts: + try: + attempts += 1 + snapshot, created = disk_to_copy.Snapshot() + break + except RuntimeError as exception: + if 'RESOURCE_OPERATION_RATE_EXCEEDED' not in str(exception) or attempts >= max_attempts: + raise exception + logger.debug('Snapshot creation throttled: Pausing {0:d} seconds'.format(backoff)) + time.sleep(backoff) + backoff ** 2 + logger.debug('Snapshot created: {0:s}'.format(snapshot.name)) new_disk = dst_project.compute.CreateDiskFromSnapshot( snapshot, disk_name_prefix='evidence', disk_type=disk_type)