mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix: add cancellation shielding to async_data_generator cleanup per Greptile review
This commit is contained in:
parent
988e43662e
commit
97bc998943
1 changed files with 12 additions and 7 deletions
|
|
@ -5146,13 +5146,18 @@ async def async_data_generator(
|
|||
# Close the response stream to release the underlying HTTP connection
|
||||
# back to the connection pool. This prevents pool exhaustion when
|
||||
# clients disconnect mid-stream.
|
||||
if hasattr(response, "aclose"):
|
||||
try:
|
||||
await response.aclose()
|
||||
except Exception as e:
|
||||
verbose_proxy_logger.debug(
|
||||
"async_data_generator: error closing response stream: %s", e
|
||||
)
|
||||
# Shield from cancellation so the close awaits can complete.
|
||||
import anyio
|
||||
|
||||
with anyio.CancelScope(shield=True):
|
||||
if hasattr(response, "aclose"):
|
||||
try:
|
||||
await response.aclose()
|
||||
except Exception as e:
|
||||
verbose_proxy_logger.debug(
|
||||
"async_data_generator: error closing response stream: %s",
|
||||
e,
|
||||
)
|
||||
|
||||
|
||||
def select_data_generator(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue