Skip to content

Commit

Permalink
lsp: Create a placeholder for a client at the given scope
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
alcarney committed Sep 29, 2024
1 parent 3e1eb23 commit c89ec6b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/esbonio/esbonio/server/features/sphinx_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,18 @@ async def get_client(self, uri: Uri) -> SphinxClient | None:
partial(self._create_or_replace_client, uri),
scope=uri,
)
# The first few callers in a given scope will miss out, but that shouldn't matter
# too much

# It's possible for this code path to be hit multiple times in quick
# succession e.g. on a fresh server start with N .rst files already open,
# creating the opportunity to accidentally spawn N duplicated clients!
#
# To prevent this, store a `None` at this scope, all being well it will be
# replaced with the actual client instance when the
# `_create_or_replace_client` callback runs.
self.clients[scope] = None

# The first few callers in a given scope will miss out, but that shouldn't
# matter too much
return None

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

0 comments on commit c89ec6b

Please sign in to comment.