-
Notifications
You must be signed in to change notification settings - Fork 657
feat(rome_lsp): stop the daemon after the last client disconnects #3643
Conversation
✅ Deploy Preview for docs-rometools ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes look good to me but I recommend terminating Rome immediately because it aligns better with what users expect.
60s is too long to avoid the LSP being outdated after upgrading the extension. I understand that VS Code stops the LSP client when updating the extension but immediately tries to connect as soon as the update is done. This happens in a few milliseconds to low seconds.
The same is the case when the user triggers the "Restart Rome LSP" command from VS Code or does a "Reload Workspace" and probably even is if the user closes VS Code and re-opens it manually to see if the problem is now "fixed".
I see that this works if we ship the fix that ensures that Rome only connects to the same version but believe that not stopping Rome can still result in a frustrating experience if Rome is in an "invalid" state (for whatever reason). The intuition of most users is to restart VS Code if they run into this problem, which won't fix their problem with a timeout of 60s.
I could shorten the timeout to maybe 10 seconds, but a grace period is required before terminating the process since as I mentioned in the PR description, the CLI opens and close a connection after spawning the daemon to ensure it works correctly. If the server was to stop immediately then the actual client requesting the name of the socket from the Rome CLI (like the editor extension or JS API) would never be able to connect as the server would have been stopped before the |
That fair but 10s is still a very long time but I see the risk that comes with reducing it to e.g. 1s or even lower.
I can see why this is necessary for an existing socket but it should be fairly unlikely that a newly created socket isn't working (and there are good reasons that re-creating the socket again won't succeed as well). Could we avoid connecting for newly created sockets instead? That still leaves the risk that the rome server terminates between |
If I remember correctly the connection test is also important for newly spawned process as the socket will be initially unresponsive and cause IO errors if the server hasn't started yet, so some specific error handling code is required there to ensure the daemon is actually ready before handing control back to the client code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should reduce the time out to 10s or even 5s.
Does the lsp-proxy
command also shut down the deamon after the timeout?
A more complete solution could be to pass a flag in the initialize
request that this is only a probing
connection or or can we manually send the exit
notification with a custom flag to NOT terminate the server.
Not very familiar with this code so could be talking nonsense, but would it help to replace a |
The implementation of the command in
The probing connection only opens a connection on the socket then immediately closes it without event sending the
The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the variable name is_oneshot
not very intuitive. How about shutdown_on_disconnect
or automatically_started
Can you update the README
of the VS Code extension to remove the known limitation of an outdated rome server as this should no longer apply.
db4be95
to
d2ebdc5
Compare
* upstream/main: fix(npm/js-api): Import type from @rometools/backend-jsonrpc (rome#3647) doc(npm/js-api): Add experimental warning to README fix(npm/js-api): Lazy load backend implementations (rome#3652) feat(rome_lsp): stop the daemon after the last client disconnects (rome#3643) fix(npm/js_api): Ensure JS API build contains `dist` folder (rome#3648) fix(rome_cli): ensures the service only connects to compatible versions (rome#3642) feat(playground): add settings button and group IR (rome#3559) release: v10.0.1 (rome#3649) fix(rome_js_analyze): False positives for interactive elements in `useKeyWithClickEvents` (rome#3644) fix(rome_js_semantic): support for object and array bindings when exporting (rome#3620) doc(editors): Clarify Rome discovery (rome#3639) fix(rome_js_analyze): improve the detection of `ReactDOM.render` calls in `noRenderReturnValue` (rome#3626) chore(npm): add license (rome#3629) Add rustdocs index Add environment Change rust docs to use Netlify fix(rome_js_analyze): useValidAnchor considering all possible expressions (rome#3599) fix(rome_js_formatter): Trailing comma inside import rome#3600 (rome#3624)
Summary
Fixes #3636
This change makes use of the existing session tracking code to schedule a background task once the last session is dropped from the server. After a short timeout (correctly set at 60 seconds), this task will broadcast the shutdown signal to the server if no new session was started in the meantime.
This behavior can be disabled by passing the
--no-timeout
flag to the__run_server
internal command, this is done automatically by therome start
command to ensure manually started instances of the server never times out. Importantly, the timeout task is only scheduled when a client disconnects, meaning a newly started server instance will run indefinitely until at least one client connects event if it wasn't passed the--no-timeout
flag (this should rarely happen if ever as the daemon spawning code tries to open a connection immediately afterward to ensure the newly created process is working correctly).Test Plan
I tested this locally by configuring the VSCode extension to use a locally built binary from this branch, and checking the
rome
process correctly stops about one minute after exiting the editor.