dotnet/runtime · error · RuntimeError

Azure failed to download

Error message

Azure failed to download

What it means

Thrown by download_with_azure() in jitutil.py when an Azure Blob Storage download fails — either during blob.download_blob() (network/auth error) or during writing the downloaded stream to the local file — and fail_if_not_found is True. The function sets ok=False on any exception and raises this error only when the caller requested hard failure.

Source

Thrown at src/coreclr/scripts/jitutil.py:649

    ok = True
    az_credential = AzureCliCredential()
    blob = BlobClient.from_blob_url(uri, credential=az_credential)
    with open(target_location, "wb") as my_blob:
        try:
            download_stream = blob.download_blob(retry_total=0)
            try:
                my_blob.write(download_stream.readall())
            except Exception as ex1:
                logging.error("Error writing data to %s", target_location)
                report_azure_error()
                ok = False
        except Exception as ex2:
            logging.error("Azure error downloading %s", uri)
            report_azure_error()
            ok = False

    if not ok and fail_if_not_found:
        raise RuntimeError("Azure failed to download")
    return ok

################################################################################
##
## File downloading functions
##
################################################################################


def download_progress_hook(count, block_size, total_size):
    """ A hook for urlretrieve to report download progress

    Args:
        count (int)               : current block index
        block_size (int)          : size of a block
        total_size (int)          : total size of a payload
    """
    sys.stdout.write("\rDownloading {0:.1f}/{1:.1f} MB...".format(min(count * block_size, total_size) / 1024 / 1024, total_size / 1024 / 1024))

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Re-authenticate with Azure CLI: 'az login'.
  2. Verify the blob URI is correct and accessible by opening it in a browser or using 'az storage blob show'.
  3. Check network connectivity to the Azure Storage endpoint.
  4. Verify write permissions and disk space for the target_location path.
  5. If the blob genuinely doesn't exist and that's acceptable, call with fail_if_not_found=False to suppress the error.

Example fix

# before: download fails with auth or 404
ok = download_with_azure(uri, target_location, fail_if_not_found=True)

# after: re-auth and handle not-found gracefully
# In shell:
az login
# In code, if 404 is acceptable:
ok = download_with_azure(uri, target_location, fail_if_not_found=False)
Defensive patterns

Strategy: retry

Validate before calling

# Verify Azure auth and blob existence before download
import subprocess
def is_azure_authenticated():
    result = subprocess.run(['az', 'account', 'show'], capture_output=True)
    return result.returncode == 0

if not is_azure_authenticated():
    print('Not authenticated. Run: az login')

Type guard

def is_azure_blob_accessible(uri: str) -> bool:
    # Quick HEAD check via urllib (for anonymous access)
    import urllib.request
    try:
        req = urllib.request.Request(uri, method='HEAD')
        urllib.request.urlopen(req, timeout=10)
        return True
    except Exception:
        return False

Try / catch

try:
    ok = download_with_azure(uri, target_location, fail_if_not_found=True)
except RuntimeError as e:
    if 'Azure failed to download' in str(e):
        logging.error('Azure download failed. Check: az login, network, blob existence.')
        # Optionally retry once after re-auth
        import subprocess
        subprocess.run(['az', 'login'])
        ok = download_with_azure(uri, target_location, fail_if_not_found=False)
    raise

Prevention

When it happens

Trigger: download_with_azure() creates a BlobClient from the URI, calls blob.download_blob(retry_total=0), and writes the stream to a local file. If either the download (line 636) or the write (line 638) raises, ok is set to False. At line 648-649: if not ok and fail_if_not_found, raise RuntimeError.

Common situations: Azure CLI authentication has expired (run 'az login' again). The blob URI is incorrect or the blob was deleted from storage (HTTP 404). Network connectivity issues or firewall blocking Azure endpoints. Insufficient local disk space or permissions to write to target_location. The Azure credentials don't have read access to the specific container/blob.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/641d62732c07a926. Report an issue: GitHub.