Skip to content

Commit 3d17699

Browse files
committed
fix(robotlangserver): remove possible deadlock in completion
1 parent 63b93af commit 3d17699

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

robotcode/language_server/common/parts/completion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ async def _text_document_completion(
128128
return None
129129

130130
@rpc_method(name="completionItem/resolve", param_type=CompletionItem)
131+
@threaded()
131132
async def _completion_item_resolve(
132133
self,
133134
params: CompletionItem,

robotcode/language_server/common/parts/formatting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None:
5454
capabilities.document_range_formatting_provider = DocumentRangeFormattingOptions(work_done_progress=True)
5555

5656
@rpc_method(name="textDocument/formatting", param_type=DocumentFormattingParams)
57+
@threaded()
5758
async def _text_document_formatting(
5859
self,
5960
params: DocumentFormattingParams,

robotcode/language_server/common/parts/rename.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING, Any, List, Optional
55

66
from ....jsonrpc2.protocol import JsonRPCErrorException, rpc_method
7-
from ....utils.async_tools import async_tasking_event
7+
from ....utils.async_tools import async_tasking_event, threaded
88
from ....utils.logging import LoggingDescriptor
99
from ..decorators import language_id_filter
1010
from ..has_extend_capabilities import HasExtendCapabilities
@@ -57,6 +57,7 @@ async def collect_prepare(
5757
...
5858

5959
@rpc_method(name="textDocument/rename", param_type=RenameParams)
60+
@threaded()
6061
async def _text_document_rename(
6162
self,
6263
text_document: TextDocumentIdentifier,
@@ -105,6 +106,7 @@ async def _text_document_rename(
105106
return result
106107

107108
@rpc_method(name="textDocument/prepareRename", param_type=PrepareRenameParams)
109+
@threaded()
108110
async def _text_document_prepare_rename(
109111
self,
110112
text_document: TextDocumentIdentifier,

robotcode/utils/async_tools.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def __init__(self) -> None:
425425
self._waiters: Optional[Deque[asyncio.Future[Any]]] = None
426426
self._locked = False
427427
self._lock = threading.RLock()
428+
self._locker: Optional[asyncio.Task[Any]] = None
428429

429430
async def __aenter__(self) -> None:
430431
await self.acquire()
@@ -439,7 +440,7 @@ def __repr__(self) -> str:
439440
extra = "locked" if self._locked else "unlocked"
440441
if self._waiters:
441442
extra = f"{extra}, waiters:{len(self._waiters)}"
442-
return f"<{res[1:-1]} [{extra}]>"
443+
return f"<{res[1:-1]} [{extra}]> {self._locker}"
443444

444445
@property
445446
def locked(self) -> bool:
@@ -449,6 +450,7 @@ async def acquire(self) -> bool:
449450
with self._lock:
450451
if not self._locked and (self._waiters is None or all(w.cancelled() for w in self._waiters)):
451452
self._locked = True
453+
self._locker = asyncio.current_task()
452454
return True
453455

454456
if self._waiters is None:
@@ -461,7 +463,7 @@ async def acquire(self) -> bool:
461463
try:
462464

463465
def aaa(fut: asyncio.Future[Any]) -> None:
464-
# warnings.warn(f"Lock takes to long {threading.current_thread()}\n{s}, try to cancel...")
466+
warnings.warn(f"Lock {self} takes to long {threading.current_thread()}\n, try to cancel...")
465467
fut.cancel()
466468

467469
# h = fut.get_loop().call_later(120, aaa, "".join(traceback.format_stack()))
@@ -481,6 +483,7 @@ def aaa(fut: asyncio.Future[Any]) -> None:
481483

482484
with self._lock:
483485
self._locked = True
486+
self._locker = asyncio.current_task()
484487

485488
return True
486489

@@ -489,6 +492,7 @@ def release(self) -> None:
489492
wake_up = False
490493
if self._locked:
491494
self._locked = False
495+
self._locker = None
492496
wake_up = True
493497

494498
if wake_up:

0 commit comments

Comments
 (0)