Skip to content

Commit 89a3805

Browse files
committed
use InternalServerError
1 parent bc6141d commit 89a3805

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

rock/admin/core/ray_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from apscheduler.schedulers.asyncio import AsyncIOScheduler
55
from apscheduler.triggers.interval import IntervalTrigger
66

7+
from rock import InternalServerRockError
78
from rock.config import RayConfig
89
from rock.logger import init_logger
9-
from rock.utils.rwlock import AsyncRWLock, WriteLockTimeout
10+
from rock.utils.rwlock import AsyncRWLock
1011

1112
logger = 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)

rock/utils/rwlock.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import asyncio
22
from contextlib import asynccontextmanager
33

4-
5-
class WriteLockTimeout(Exception):
6-
pass
4+
from rock import InternalServerRockError
5+
from rock._codes import codes
76

87

98
class 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:

tests/unit/utils/test_rwlock_timeout.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import 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

0 commit comments

Comments
 (0)