Skip to content

Commit 27d781c

Browse files
committed
fix(robotlangserver): remove possible deadlock in Namespace initialization
1 parent aa8e4d3 commit 27d781c

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

robotcode/language_server/robotframework/diagnostics/namespace.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,10 @@ class DataEntry(NamedTuple):
779779

780780
@_logger.call(condition=lambda self: not self._initialized)
781781
async def ensure_initialized(self) -> bool:
782-
async with self._initialize_lock:
783-
imports_changed = False
782+
run_initialize = False
783+
imports_changed = False
784784

785+
async with self._initialize_lock:
785786
if not self._initialized:
786787

787788
if self._in_initialize:
@@ -804,14 +805,7 @@ async def ensure_initialized(self) -> bool:
804805
elif old_imports != imports:
805806
imports_changed = True
806807

807-
new_imports = []
808-
for e in old_imports:
809-
if e in imports:
810-
new_imports.append(e)
811-
for e in imports:
812-
if e not in new_imports:
813-
new_imports.append(e)
814-
self.document.set_data(Namespace, new_imports)
808+
self.document.set_data(Namespace, imports)
815809
self.document.set_data(Namespace.DataEntry, None)
816810
else:
817811
data_entry = self.document.get_data(Namespace.DataEntry)
@@ -849,6 +843,7 @@ async def ensure_initialized(self) -> bool:
849843
await self._reset_global_variables()
850844

851845
self._initialized = True
846+
run_initialize = True
852847

853848
except BaseException as e:
854849
if not isinstance(e, asyncio.CancelledError):
@@ -863,7 +858,7 @@ async def ensure_initialized(self) -> bool:
863858
finally:
864859
self._in_initialize = False
865860

866-
if self._initialized:
861+
if run_initialize:
867862
await self.has_initialized(self)
868863

869864
if imports_changed:

robotcode/utils/async_tools.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import inspect
88
import threading
99
import time
10-
import traceback
1110
import warnings
1211
import weakref
1312
from collections import deque
@@ -461,11 +460,12 @@ async def acquire(self) -> bool:
461460
try:
462461
try:
463462

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

468-
h = fut.get_loop().call_later(120, aaa, "".join(traceback.format_stack()))
467+
# h = fut.get_loop().call_later(120, aaa, "".join(traceback.format_stack()))
468+
h = fut.get_loop().call_later(120, aaa, fut)
469469

470470
await fut
471471

0 commit comments

Comments
 (0)