Fixed a crash on completions with auto-imports racing with DidClose notification#2905
Fixed a crash on completions with auto-imports racing with DidClose notification#2905Andarist wants to merge 14 commits intomicrosoft:mainfrom
DidClose notification#2905Conversation
|
I have a branch with this in it as well that I passed off to @gabritto as she was working on fixing a related crash. I think my branch wasn't quite right or was insufficient; I'm not sure what the status is. However, in mine, after we clone the snapshot for auto-imports, we check to see if the session can adopt the new one as the latest snapshot - I think we'll want that functionality. |
There was a problem hiding this comment.
I couldn't really test this through fourslash so I had to resort to rolling a new test file that could use the NewLSPClient directly with a greater control over the performed actions.
There was a problem hiding this comment.
Couldn't we write a test using session directly? I did this recently in https://github.com/microsoft/typescript-go/blob/main/internal/project/snapshot_test.go#L125 to test things related to the timing of changes being processed.
We may need a better testing setup for those kinds of bugs long-term, but maybe right now using session for testing could do.
There was a problem hiding this comment.
I planned to add a test using the session directly later on. I just wanted to have more real-life test cases for this too and focused on those here.
| } | ||
| return nil, nil, fmt.Errorf("no project found for URI %s", uri) | ||
| } | ||
|
|
There was a problem hiding this comment.
@Andarist Here's how I was doing the work of re-using the snapshot + extra information computed in an old PR:
https://github.com/microsoft/typescript-go/pull/1871/changes#diff-b8a62f01d8c9b6ed8df3c61e62fe4b694885da67eadb682a4117ce2cb62b1bf9R754-R784
But the tricky part would be to figure out whether to release the snapshot or not, I'll have to think about that.
There was a problem hiding this comment.
I think for the snapshot lifetime handling, we can (1) invoke snapshot.dispose() inside snapshot.Deref() when the count reaches 0, and (2) make sure both session and the server call .Ref() and .Deref() when they acquire/release it. So if you did the whole thing I linked above of enqueuing of a snapshot with auto-imports to see if session can adopt it, that would come with a call to .Ref()/.Deref(), etc.
1c0137d to
bdf37cf
Compare
bdf37cf to
0c47159
Compare
Root cause behind the crash:
ErrNeedsAutoImportsDidCloseor some other change)DidClose) and resends the adjusted requestspecifierCacheand the request panicsThere are 2 fixes in this PR:
change.RequestedFile. That entry isn't removed from thespecifierCache. It's not up to the server to cancel a pending request even if the state changed.fixes #2882