Merge pull request #15717 from sihyeonn/fix/sh-cleanup

fix: improve cleanup_response positioning for better resource management
This commit is contained in:
Tim Jaeryang Baek 2025-07-15 22:48:10 +04:00 committed by GitHub
commit ae716bddee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 13 deletions

View file

@ -184,7 +184,6 @@ async def send_post_request(
) )
else: else:
res = await r.json() res = await r.json()
await cleanup_response(r, session)
return res return res
except HTTPException as e: except HTTPException as e:
@ -196,6 +195,9 @@ async def send_post_request(
status_code=r.status if r else 500, status_code=r.status if r else 500,
detail=detail if e else "Open WebUI: Server Connection Error", detail=detail if e else "Open WebUI: Server Connection Error",
) )
finally:
if not stream:
await cleanup_response(r, session)
def get_api_key(idx, url, configs): def get_api_key(idx, url, configs):

View file

@ -893,10 +893,8 @@ async def generate_chat_completion(
detail=detail if detail else "Open WebUI: Server Connection Error", detail=detail if detail else "Open WebUI: Server Connection Error",
) )
finally: finally:
if not streaming and session: if not streaming:
if r: await cleanup_response(r, session)
r.close()
await session.close()
async def embeddings(request: Request, form_data: dict, user): async def embeddings(request: Request, form_data: dict, user):
@ -975,10 +973,8 @@ async def embeddings(request: Request, form_data: dict, user):
detail=detail if detail else "Open WebUI: Server Connection Error", detail=detail if detail else "Open WebUI: Server Connection Error",
) )
finally: finally:
if not streaming and session: if not streaming:
if r: await cleanup_response(r, session)
r.close()
await session.close()
@router.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"]) @router.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
@ -1074,7 +1070,5 @@ async def proxy(path: str, request: Request, user=Depends(get_verified_user)):
detail=detail if detail else "Open WebUI: Server Connection Error", detail=detail if detail else "Open WebUI: Server Connection Error",
) )
finally: finally:
if not streaming and session: if not streaming:
if r: await cleanup_response(r, session)
r.close()
await session.close()