Skip to content

Commit afbc239

Browse files
committed
Error handling in the download manager
1 parent 55bed56 commit afbc239

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/textual_serve/download_manager.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,31 @@ async def download(self, delivery_key: str) -> AsyncGenerator[bytes, None]:
9090

9191
while True:
9292
# Request a chunk from the app service.
93-
await app_service.send_meta(
93+
send_result = await app_service.send_meta(
9494
{
9595
"type": "deliver_chunk_request",
9696
"key": delivery_key,
9797
"size": DOWNLOAD_CHUNK_SIZE,
9898
}
9999
)
100100

101-
chunk = await incoming_chunks.get()
101+
if not send_result:
102+
log.warning(
103+
"Download {delivery_key!r} failed to request chunk from app service"
104+
)
105+
del self._active_downloads[delivery_key]
106+
break
107+
108+
try:
109+
chunk = await asyncio.wait_for(incoming_chunks.get(), DOWNLOAD_TIMEOUT)
110+
except asyncio.TimeoutError:
111+
log.warning(
112+
"Download %r failed to receive chunk from app service within %r seconds",
113+
delivery_key,
114+
DOWNLOAD_TIMEOUT,
115+
)
116+
chunk = None
117+
102118
if not chunk:
103119
# Empty chunk - the app process has finished sending the file.
104120
incoming_chunks.task_done()

0 commit comments

Comments
 (0)