llama-stack-mirror/llama_stack/distribution/server
Ben Browning 45ef6eac10 fix: properly handle streaming client disconnects
Previously, when a streaming client would disconnect before we were
finished streaming the entire response, an error like the below would
get raised from the `sse_generator` function in
`llama_stack/distribution/server/server.py`:

```
AttributeError: 'coroutine' object has no attribute 'aclose'. Did you mean: 'close'?
```

This was because we were calling `aclose` on a coroutine instead of
the awaited value from that coroutine. This change fixes that, so that
we save off the awaited value and then can call `aclose` on it if we
encounter an `asyncio.CancelledError`, like we see when a client
disconnects before we're finished streaming.

The other changes in here are to add a simple set of tests for the
happy path of our SSE streaming and this client disconnect path.

That unfortunately requires adding one more dependency into our unit
test section of pyproject.toml since `server.py` requires loading some
of the telemetry code for me to test this functionality.

Signed-off-by: Ben Browning <bbrownin@redhat.com>
2025-04-21 16:10:45 -04:00
..
__init__.py API Updates (#73) 2024-09-17 19:51:35 -07:00
auth.py feat(server): add attribute based access control for resources (#1703) 2025-03-19 21:28:52 -07:00
endpoints.py feat(telemetry): clean up spans (#1760) 2025-03-21 20:05:11 -07:00
server.py fix: properly handle streaming client disconnects 2025-04-21 16:10:45 -04:00