File tree Expand file tree Collapse file tree 3 files changed +13
-8
lines changed
Expand file tree Collapse file tree 3 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 44from apscheduler .schedulers .asyncio import AsyncIOScheduler
55from apscheduler .triggers .interval import IntervalTrigger
66
7+ from rock import InternalServerRockError
78from rock .config import RayConfig
89from rock .logger import init_logger
9- from rock .utils .rwlock import AsyncRWLock , WriteLockTimeout
10+ from rock .utils .rwlock import AsyncRWLock
1011
1112logger = init_logger (__name__ )
1213
@@ -73,5 +74,5 @@ async def _reconnect_ray(self):
7374 logger .info (
7475 f"current time { end_time } , Reconnect ray cluster successfully, duration { end_time - start_time } s"
7576 )
76- except WriteLockTimeout as e :
77+ except InternalServerRockError as e :
7778 logger .warning ("Reconnect ray cluster timeout, skip reconnectting" , exc_info = e )
Original file line number Diff line number Diff line change 11import asyncio
22from contextlib import asynccontextmanager
33
4-
5- class WriteLockTimeout (Exception ):
6- pass
4+ from rock import InternalServerRockError
5+ from rock ._codes import codes
76
87
98class AsyncRWLock :
@@ -94,7 +93,11 @@ async def release_write(self):
9493 async def write_lock (self , timeout = None ):
9594 ready = await self .acquire_write (timeout = timeout )
9695 if not ready :
97- raise WriteLockTimeout ()
96+ raise InternalServerRockError (
97+ f"Failed to acquire write lock within { timeout } seconds. "
98+ "This may indicate a deadlock or excessive lock contention in background jobs." ,
99+ code = codes .INTERNAL_SERVER_ERROR ,
100+ )
98101 try :
99102 yield
100103 finally :
Original file line number Diff line number Diff line change 22
33import pytest
44
5- from rock .utils .rwlock import AsyncRWLock , WriteLockTimeout
5+ from rock import InternalServerRockError
6+ from rock .utils .rwlock import AsyncRWLock
67
78
89@pytest .mark .asyncio
@@ -12,7 +13,7 @@ async def test_rwlock_write_timeout_then_read_lock_ok():
1213 lock ._readers = 1
1314
1415 async def writer ():
15- with pytest .raises (WriteLockTimeout ):
16+ with pytest .raises (InternalServerRockError ):
1617 async with lock .write_lock (timeout = 5 ):
1718 pytest .fail ("write_lock should have timed out and not enter this block" )
1819
You can’t perform that action at this time.
0 commit comments