Skip to content

Conversation

@dlqqq
Copy link
Collaborator

@dlqqq dlqqq commented May 14, 2025

Description

yprovider.ts deletes the client YDoc & stops retrying the connection only when the WS close code is 1006. This indicates an unexpected closure (e.g. via kill -9 <PID>). However, our backend should close each WebSocket gracefully before exiting; this sends close code 1000, which gets ignored by yprovider.ts. This causes re-connect attempts to fire constantly from outdated clients after the server is restarted.

This PR simply removes the if (event.code === 1006) condition and always deletes the client YDoc & stops retrying the connection on disconnect. This fixes #39 and prevents content duplication when an outdated client connects to a new server session.

While this PR does fix the edge cases, it also worsens the experience for users with a flaky internet connection, who now have to refresh the page manually every time they are disconnected. We can improve this in future PRs; I've identified ways to handle client disconnects more gracefully in a new issue: #45.

@dlqqq dlqqq force-pushed the fix-reconnect-bug branch from 7782f7a to 49c2bbd Compare May 14, 2025 21:33
@3coins
Copy link
Collaborator

3coins commented May 14, 2025

This is still happening for me, after any refresh (even without restarting the server).

Screen.Recording.2025-05-14.at.3.00.23.PM.mov

@dlqqq
Copy link
Collaborator Author

dlqqq commented May 14, 2025

@3coins This might be because you need to rebuild the frontend before trying to reproduce the original bug. The sequencing is a bit tricky. Can you try these steps below?

  1. Checkout & pull this branch
  2. Run jlpm && jlpm build
  3. Run jupyter lab to open a new window
  4. Kill jupyter lab and restart it
  5. The original (first) window should no longer constantly re-connect

Copy link
Collaborator

@3coins 3coins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Was able to verify that during server disconnects, clients don't try to re-connect, but show a dialog to refresh page. The browser refresh issue mentioned in one of my comments is being tracked in #51 and is a different problem.

@Zsailer Zsailer merged commit 0f39bb1 into jupyter-ai-contrib:main May 16, 2025
2 of 6 checks passed
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.

Repeated handshakes on outdated clients

3 participants