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

fix: ensure ending a session triggers listeners #2518

Merged
merged 3 commits into from
Sep 29, 2024
Merged

Conversation

rchl
Copy link
Member

@rchl rchl commented Sep 21, 2024

I was looking into introducing some global session listener concept for plugin use but while doing so I found out that on closing a session we don't trigger various lifecycle listeners that we should be triggering. It appears that Session is deleted before Transport is closed so Session.on_transport_close and following logic is not executed.

The one-line fix is to change self._sessions in WindowManager from WeakSet[Session] to set[Session].

I'm not sure why we are using WeakSet here. There could be a valid reason when this makes sense or it could be due to old convention where we've relied more on GC than on explicitly notifying when Session/SessionView/SessionBuffer are closed.

(I've also left a bunch of logs that I'm of course planning to remove but those can be used to see the difference with and without this fix when closing the last file of some session, for example.)

@rchl
Copy link
Member Author

rchl commented Sep 21, 2024

Logs on closing the last file of a session

Without the fix:

[DocumentListener] _clear_session_views_async
[Session] end_async False
[Session] Sending shutdown
[Session] Closing transport
[Session] __del__ LSP-typescript
[ProcessTransport] end Transport None

With the fix:

[DocumentListener] _clear_session_views_async
[Session] end_async False
[Session] Sending shutdown
[Session] Closing transport
[ProcessTransport] end Transport <LSP.plugin.core.sessions.Session object at 0x1058472b0>
[Session] on_transport-close
[WindowManager] on_post_exit_async LSP-typescript
[Session] __del__ LSP-typescript

Copy link

netlify bot commented Sep 29, 2024

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit cc7c42c
🔍 Latest deploy log https://app.netlify.com/sites/sublime-lsp/deploys/66f938a57f44000008a384b9
😎 Deploy Preview https://deploy-preview-2518--sublime-lsp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@rchl
Copy link
Member Author

rchl commented Sep 29, 2024

Even after the changes:

  • On closing a window the WindowManager.destroy() is called and it ends and removes all sessions from the set so the listeners are not called in this case. This is perhaps OK.
  • On restarting a session the WindowManager.restart_sessions_async() is called and it also ends the session and removes it from the set immediately so the listeners are also not called. This might not be ideal since a proper cleanup might not happen. We have to also keep in mind that session can restart before the previous one fully shut down (Wrong SessionView destroyed on restarting session #2258) so doing a seemingly correct fix could introduce issues.

@rchl rchl changed the title fix: ensure ending a session triggers various listeners fix: ensure ending a session triggers listeners Sep 29, 2024
@rchl rchl merged commit 7a037da into main Sep 29, 2024
8 checks passed
@rchl rchl deleted the fix/shutdown-listeners branch September 29, 2024 11:26
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

Successfully merging this pull request may close these issues.

1 participant