Skip to content

Commit 482ad6f

Browse files
authored
Increase backup upload timeout (#132990)
1 parent 77fb440 commit 482ad6f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

homeassistant/components/cloud/backup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import hashlib
88
from typing import Any, Self
99

10-
from aiohttp import ClientError, StreamReader
10+
from aiohttp import ClientError, ClientTimeout, StreamReader
1111
from hass_nabucasa import Cloud, CloudError
1212
from hass_nabucasa.cloud_api import (
1313
async_files_delete_file,
@@ -151,9 +151,10 @@ async def async_upload_backup(
151151
details["url"],
152152
data=await open_stream(),
153153
headers=details["headers"] | {"content-length": str(backup.size)},
154+
timeout=ClientTimeout(connect=10.0, total=43200.0), # 43200s == 12h
154155
)
155156
upload_status.raise_for_status()
156-
except ClientError as err:
157+
except (TimeoutError, ClientError) as err:
157158
raise BackupAgentError("Failed to upload backup") from err
158159

159160
async def async_delete_backup(

tests/components/cloud/test_backup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,15 @@ async def test_agents_upload(
372372
assert f"Uploading backup {backup_id}" in caplog.text
373373

374374

375+
@pytest.mark.parametrize("put_mock_kwargs", [{"status": 500}, {"exc": TimeoutError}])
375376
@pytest.mark.usefixtures("cloud_logged_in", "mock_list_files")
376377
async def test_agents_upload_fail_put(
377378
hass: HomeAssistant,
378379
hass_client: ClientSessionGenerator,
379380
caplog: pytest.LogCaptureFixture,
380381
aioclient_mock: AiohttpClientMocker,
381382
mock_get_upload_details: Mock,
383+
put_mock_kwargs: dict[str, Any],
382384
) -> None:
383385
"""Test agent upload backup fails."""
384386
client = await hass_client()
@@ -395,7 +397,7 @@ async def test_agents_upload_fail_put(
395397
protected=True,
396398
size=0.0,
397399
)
398-
aioclient_mock.put(mock_get_upload_details.return_value["url"], status=500)
400+
aioclient_mock.put(mock_get_upload_details.return_value["url"], **put_mock_kwargs)
399401

400402
with (
401403
patch(

0 commit comments

Comments
 (0)