mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(proxy): take the write-slot advisory lock before member name checks
Bugbot flagged that the member create path ran its name-collision check without any lock, so two concurrent creates of the same name could both pass. Take the same pg_advisory_xact_lock main takes at the top of the write transaction so member writes serialize before the checks run.
This commit is contained in:
parent
77915d43b8
commit
e39e1c8dea
1 changed files with 5 additions and 0 deletions
|
|
@ -321,6 +321,10 @@ def _member_auto_router_marker_for_update(
|
||||||
return incoming_params.model is None or incoming_params.model == _effective_model(None, existing.litellm_params)
|
return incoming_params.model is None or incoming_params.model == _effective_model(None, existing.litellm_params)
|
||||||
|
|
||||||
|
|
||||||
|
AUTO_ROUTER_WRITE_SLOT_LOCK_KEY: Final = 5_872_301
|
||||||
|
_WRITE_SLOT_LOCK_SQL: Final = "SELECT 1 AS locked FROM pg_advisory_xact_lock($1)"
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def _member_auto_router_write_slot(
|
async def _member_auto_router_write_slot(
|
||||||
prisma_client: PrismaClient,
|
prisma_client: PrismaClient,
|
||||||
|
|
@ -345,6 +349,7 @@ async def _member_auto_router_write_slot(
|
||||||
transaction_client: Final = _ModelTransactionClient.model_validate(prisma_client.db)
|
transaction_client: Final = _ModelTransactionClient.model_validate(prisma_client.db)
|
||||||
async with transaction_client.tx(timeout=datetime.timedelta(seconds=30)) as tx_ctx:
|
async with transaction_client.tx(timeout=datetime.timedelta(seconds=30)) as tx_ctx:
|
||||||
tables: Final[_TxModelTables] = tx_ctx
|
tables: Final[_TxModelTables] = tx_ctx
|
||||||
|
await tx_ctx.query_raw(_WRITE_SLOT_LOCK_SQL, AUTO_ROUTER_WRITE_SLOT_LOCK_KEY)
|
||||||
config_rows: Final = () if llm_router is None else tuple(llm_router.config_deployments())
|
config_rows: Final = () if llm_router is None else tuple(llm_router.config_deployments())
|
||||||
if member_write.model_id is not None:
|
if member_write.model_id is not None:
|
||||||
await tx_ctx.query_raw(
|
await tx_ctx.query_raw(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue