Skip to content

Commit 32595ea

Browse files
pupachaLiliDeng
authored andcommitted
azure: handle PendingCopyOperation error during vhd copy
When multiple LISA runs use the same VHD URL concurrently, Azure may throw the following error during start_copy_from_url: ResourceExistsError: There is currently a pending copy operation. This happens because multiple runs attempt to copy the VHD to the same destination. Although a lock prevents this within a single LISA run, it can still occur across multiple runs. To handle this, catch the exception and gracefully continue with wait_copy_blob.
1 parent 536bcef commit 32595ea

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lisa/sut_orchestrator/azure/common.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -1934,9 +1934,26 @@ def copy_vhd_to_storage(
19341934
log=log,
19351935
)
19361936
else:
1937-
blob_client.start_copy_from_url(
1938-
src_vhd_sas_url, metadata=None, incremental_copy=False
1939-
)
1937+
# When multiple LISA runs use the same VHD URL concurrently, Azure may
1938+
# throw the following error during start_copy_from_url:
1939+
#
1940+
# ResourceExistsError: There is currently a pending copy operation.
1941+
#
1942+
# This happens because multiple runs attempt to copy the VHD to the same
1943+
# destination. Although a lock prevents this within a single LISA run,
1944+
# it can still occur across multiple runs. To handle this, catch the
1945+
# exception and gracefully continue with wait_copy_blob.
1946+
try:
1947+
blob_client.start_copy_from_url(
1948+
src_vhd_sas_url, metadata=None, incremental_copy=False
1949+
)
1950+
except ResourceExistsError as e:
1951+
if "PendingCopyOperation" in str(e):
1952+
log.warning(
1953+
"Pending copy operation detected. Avoid copying again"
1954+
)
1955+
else:
1956+
raise e
19401957

19411958
wait_copy_blob(blob_client, dst_vhd_name, log)
19421959

@@ -1979,7 +1996,7 @@ def wait_copy_blob(
19791996
log: Logger,
19801997
timeout: int = 60 * 60,
19811998
) -> None:
1982-
log.info(f"copying vhd: {vhd_path}")
1999+
log.info(f"Waiting for copying vhd: {vhd_path}")
19832000
if blob_client.get_blob_properties().copy.status:
19842001
check_till_timeout(
19852002
lambda: blob_client.get_blob_properties().copy.status == "success",

0 commit comments

Comments
 (0)