From d5bb71fb489336d124bde08afefdad7963d9df4c Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Mon, 11 Dec 2023 22:11:55 -0800 Subject: [PATCH] (fix) proxy : cleanup router --- litellm/proxy/proxy_server.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 31951155f2..a6da29cf3e 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -874,16 +874,6 @@ async def startup_event(): # add master key to db await generate_key_helper_fn(duration=None, models=[], aliases={}, config={}, spend=0, token=master_key) -@router.on_event("shutdown") -async def shutdown_event(): - global prisma_client, master_key, user_custom_auth - if prisma_client: - print("Disconnecting from Prisma") - await prisma_client.disconnect() - - ## RESET CUSTOM VARIABLES ## - master_key = None - user_custom_auth = None #### API ENDPOINTS #### @router.get("/v1/models", dependencies=[Depends(user_api_key_auth)]) @@ -1467,4 +1457,27 @@ async def get_routes(): return {"routes": routes} +@router.on_event("shutdown") +async def shutdown_event(): + global prisma_client, master_key, user_custom_auth + if prisma_client: + print("Disconnecting from Prisma") + await prisma_client.disconnect() + + ## RESET CUSTOM VARIABLES ## + cleanup_router_config_variables() + +def cleanup_router_config_variables(): + global master_key, user_config_file_path, otel_logging, user_custom_auth, user_custom_auth_path, use_background_health_checks, health_check_interval + + # Set all variables to None + master_key = None + user_config_file_path = None + otel_logging = None + user_custom_auth = None + user_custom_auth_path = None + use_background_health_checks = None + health_check_interval = None + + app.include_router(router)