Description
So @rjmholt and I have been debugging an issue with the PowerShell extension after updating to v3.19, and we believe have tracked it down to a race condition. But we don't know if this is an issue with OmniSharp, or maybe even with the LSP spec itself.
We see that the Initialize
request handler, for LSP2, sets Initialized
:
csharp-language-server-protocol/src/Server/LanguageServer.cs
Lines 316 to 322 in 005c87f
This made sense, because Initialize
was a request and so the client can (and does) wait to hear from the server that Initialize
was handled. When OmniSharp calls that initialized()
method (for LSP2) then GetRequests()
starts behaving "correctly" (handling all notifications and requests):
csharp-language-server-protocol/src/Server/LspServerReceiver.cs
Lines 20 to 54 in 1b6788d
But then this was changed for LSP3, we have an Initialized
(note the D) handler for the Initialized
notification (which the client cannot wait on). This is problematic because the client then sends more notifications which race the server's handler for the Initialized
notification, and this race ends up in the requests not being handled, as evidenced by the responses "Unexpected request" and "Unexpected notification" in GetRequests
.
csharp-language-server-protocol/src/Server/LanguageServer.cs
Lines 327 to 337 in 005c87f
This correlates with the logs we have when we see a bug in the PowerShell extension:
2021-05-06 11:41:07.210 -07:00 [DBG] Finding descriptors for initialize
2021-05-06 11:41:07.382 -07:00 [DBG] Queueing "Serial":initialize:0 request for processing
2021-05-06 11:41:07.428 -07:00 [DBG] Starting: Processing request initialize 0
2021-05-06 11:41:07.444 -07:00 [DBG] Starting: Routing Request (0) initialize
2021-05-06 11:41:08.131 -07:00 [DBG] Finished: Routing Request (0) initialize in 687ms
2021-05-06 11:41:08.131 -07:00 [DBG] Finished: Processing request initialize 0 in 702ms
2021-05-06 11:41:08.211 -07:00 [DBG] Finding descriptors for initialized
2021-05-06 11:41:08.211 -07:00 [DBG] Queueing "Serial":initialized request for processing
2021-05-06 11:41:08.232 -07:00 [WRN] Unexpected notification workspace/didChangeConfiguration {"Method":"workspace/didChangeConfiguration","Params":[[[[[[[[[]],[[]]]],[[]],[[]],[[]],[[]],[[]],[[[[]],[[]]]],[[]],[[]],[[]],[[[[]]]],[[]],[[]],[[[[]],[[]]]],[[[[]],[[]]]],[[[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]]]],[[[[]],[[]],[[]],[[]],[[]]]],[[[[]]]],[[[[]],[[]],[[]],[[]],[[]]]],[[[[]],[[]],[[]]]],[[[[]],[[]]]]]],[[[[[[]]]],[[[[]],[[]],[[]],[[]],[[]]]],[[[[]],[[]]]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[[[]],[[]],[[]],[[]]]],[[]],[[]],[[]],[[]],[[]],[[[[]]]]]],[[[[[[]],[[]],[[]]]],[[]],[[]],[[]],[[]],[[]],[[[[]],[[]],[[null]]]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[]],[[[[]],[[]],[[]]]],[[]]]]]]],"TraceParent":null,"TraceState":null,"$type":"Notification"}
2021-05-06 11:41:08.233 -07:00 [WRN] Unexpected request powerShell/getVersion {"Id":1,"Method":"powerShell/getVersion","Params":null,"TraceParent":null,"TraceState":null,"$type":"Request"}
2021-05-06 11:41:08.234 -07:00 [WRN] Tried to send request or notification before initialization was completed and will be sent later {"Id":null,"Error":{"Code":-32002,"Data":null,"Message":"Server Not Initialized","$type":"ErrorMessage"},"Method":"powerShell/getVersion","$type":"ServerNotInitialized"}
2021-05-06 11:41:08.234 -07:00 [DBG] Starting: Processing notification initialized
2021-05-06 11:41:08.243 -07:00 [DBG] Starting: Routing Notification initialized
2021-05-06 11:41:08.366 -07:00 [DBG] Finished: Routing Notification initialized in 132ms
2021-05-06 11:41:08.366 -07:00 [DBG] Finished: Processing notification initialized in 141ms
We think this may be related to #556, @david-driscoll was there any update on your investigation into that issue? @majastrz does any of this make sense to you and sound related to your issue?