Skip to content

Commit

Permalink
ext: fix issues in net gc task (#7904)
Browse files Browse the repository at this point in the history
* don't run on dropping databases
* don't call asyncio.wait([])
* fix wrong logging without decoding JSON
  • Loading branch information
fantix authored Oct 23, 2024
1 parent d01b12f commit a72c8d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
16 changes: 11 additions & 5 deletions edb/server/net_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ def _warn(e):
)
async for iteration in rloop:
async with iteration:
result = await execute.parse_execute_json(
if not db.tenant.is_database_connectable(db.name):
# Don't run the net_worker if the database is not
# connectable, e.g. being dropped
continue
result_json = await execute.parse_execute_json(
db,
"""
with requests := (
Expand All @@ -274,14 +278,15 @@ def _warn(e):
and (datetime_of_statement() - .updated_at) >
<duration>$expires_in
)
delete requests;
select count((delete requests));
""",
variables={"expires_in": expires_in.to_backend_str()},
cached_globally=True,
tx_isolation=defines.TxIsolationLevel.RepeatableRead,
)
if len(result) > 0:
logger.info(f"Deleted requests: {result!r}")
result: list[int] = json.loads(result_json)
if result[0] > 0:
logger.info(f"Deleted {result[0]} requests")
else:
logger.info(f"No requests to delete")

Expand Down Expand Up @@ -311,7 +316,8 @@ async def gc(server: edbserver.BaseServer) -> None:
if tenant.accept_new_tasks
]
try:
await asyncio.wait(tasks)
if tasks:
await asyncio.wait(tasks)
except Exception as ex:
logger.debug(
"GC of std::net::http::ScheduledRequest failed", exc_info=ex
Expand Down
30 changes: 18 additions & 12 deletions edb/server/protocol/auth_ext/pkce.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,29 @@ async def delete(db: edbtenant.dbview.Database, id: str) -> None:
assert len(result_json) == 1


async def _delete_challenge(db: edbtenant.dbview.Database) -> None:
if not db.tenant.is_database_connectable(db.name):
# Don't run gc if the database is not connectable, e.g. being dropped
return

await execute.parse_execute_json(
db,
"""
delete ext::auth::PKCEChallenge filter
(datetime_of_statement() - .created_at) >
<duration>$validity
""",
variables={"validity": VALIDITY.to_backend_str()},
cached_globally=True,
)


async def _gc(tenant: edbtenant.Tenant) -> None:
try:
async with asyncio.TaskGroup() as g:
for db in tenant.iter_dbs():
if "auth" in db.extensions:
g.create_task(
execute.parse_execute_json(
db,
"""
delete ext::auth::PKCEChallenge filter
(datetime_of_statement() - .created_at) >
<duration>$validity
""",
variables={"validity": VALIDITY.to_backend_str()},
cached_globally=True,
),
)
g.create_task(_delete_challenge(db))
except Exception as ex:
logger.debug(
"GC of ext::auth::PKCEChallenge failed (instance: %s)",
Expand Down

0 comments on commit a72c8d9

Please sign in to comment.