Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands.state can contain invalid data #794

Closed
Booksbaum opened this issue Jun 15, 2021 · 2 comments
Closed

Commands.state can contain invalid data #794

Booksbaum opened this issue Jun 15, 2021 · 2 comments

Comments

@Booksbaum
Copy link
Contributor

In the "Auto-Open from completion" tests (for #788) I forgot to Cache the created LSP Server. But after adding Async.Cache some tests suddenly failed. Even worse: In different test runs different tests failed.... Test failure was: Returned open position was different from expected position.

So I investigated:

  • Commands.Completion (textDocument/completion request) returns immediately all found Completion items, and triggers a background collection of details (like Namespace insert location) for the completions.
  • Commands.HelpText (completionItem/resolve request) then returns the actual details for a specific Item (Regex in tests). Depending on the progress of the background collection (triggered in Commands.Completion) the details might come from cache (state.HelpText) or are generated on the fly.

BUT: Because the cache is filled in the background, a new incoming Completion request might invalidate the current cache. But the Background Job still fills the cache -- now with outdated data.

To test:

  • Get code (Booksbaum@a099302):
    git clone https://github.com/Booksbaum/FsAutoComplete.git FsAutoCompleteState
    cd FsAutoCompleteState
    git checkout a0993023a25e189f6b384ad4deaefb4a31e4474b
    
  • Move into dir with test project: cd test\FsAutoComplete.Tests.Lsp
  • Run tests: dotnet run (It runs only a couple of focused tests)
  • Most likely at least one test will fail (if not: run again)
    • I introduced a version to track the cache
      -> look for messages like
      [13:12:40 ERR] [Test] versions don't match: current v11 <> v10 cached
      [13:12:40 ERR] [Test] different NsInsert: expected={"Column": 2, "Line": 40, "$type": "<>f__AnonymousType685321008`2"}; cached={"Column": 4, "Line": 34, "$type": "<>f__AnonymousType685321008`2"}
      

In sequence diagram:

In Code:

state.{Declarations; HelpText CompletionNamespaceInsert; CurrentAst} are only used in Commands.Completion (and its background job) and Commands.HelpText.
But the same issue probably occurs for the other data in state.

It's probably not an issue that occurs often when using the LSP Server in an editor -- after all actions here are mostly human driven ... and as such quite slow. (Even the CI build seems to be 'too slow' and the issue doesn't occur -- only in local test runs (with a decently speedy PC))



For testing I made a simple "fix": Instead of just the namespace as dictionary key, I additional add a id (or version) unique for each Commands.Completion call -> background job still writes old data, but that gets ignored because it has an old id.
That allows the tests to run with a cached server.
See commit Booksbaum@93bc02e

But it's unfortunately not a real fix: All things are still async and might be out of order. With that id it's just way less likely for the issue to emerge...
(Additional: Currently only some caches in State are gated)

@TheAngryByrd
Copy link
Member

Since we've moved to AdaptiveLSPServer as default, do you think it's worth keeping this open?

@Booksbaum
Copy link
Contributor Author

Yes, I think we can consider this here outdated. AdaptiveLSPServer doesn't even use Commands.Completion & Commands.HelpText any more.

-> Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants