Skip to content

Commit c89ec6b

Browse files
committed
lsp: Create a placeholder for a client at the given scope
When `manager.get_client` is called many times in quick succession (such as on server restart with N files open) this can fool the `SphinxManager` into creating multiple client instances for a given configuration scope. By storing a ``None`` at the relevant scope we allow the SphinxManager to detect that the scope has already been handled, preventing the spawning of duplicated client instances. This should, finally, fix the flaky test issue (#859)
1 parent 3e1eb23 commit c89ec6b

File tree

1 file changed

+12
-2
lines changed
  • lib/esbonio/esbonio/server/features/sphinx_manager

1 file changed

+12
-2
lines changed

lib/esbonio/esbonio/server/features/sphinx_manager/manager.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,18 @@ async def get_client(self, uri: Uri) -> SphinxClient | None:
238238
partial(self._create_or_replace_client, uri),
239239
scope=uri,
240240
)
241-
# The first few callers in a given scope will miss out, but that shouldn't matter
242-
# too much
241+
242+
# It's possible for this code path to be hit multiple times in quick
243+
# succession e.g. on a fresh server start with N .rst files already open,
244+
# creating the opportunity to accidentally spawn N duplicated clients!
245+
#
246+
# To prevent this, store a `None` at this scope, all being well it will be
247+
# replaced with the actual client instance when the
248+
# `_create_or_replace_client` callback runs.
249+
self.clients[scope] = None
250+
251+
# The first few callers in a given scope will miss out, but that shouldn't
252+
# matter too much
243253
return None
244254

245255
if (client := self.clients[scope]) is None:

0 commit comments

Comments
 (0)