Skip to content

add websocket pings/pongs to help close zombie connections#410

Merged
rolyatmax merged 1 commit into
mainfrom
taylor/add-ping-pong-to-websocket-server
Sep 15, 2025
Merged

add websocket pings/pongs to help close zombie connections#410
rolyatmax merged 1 commit into
mainfrom
taylor/add-ping-pong-to-websocket-server

Conversation

@rolyatmax

Copy link
Copy Markdown
Member

No description provided.

@rolyatmax
rolyatmax requested a review from paulgb September 15, 2025 19:28
@vercel

vercel Bot commented Sep 15, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
y-sweet-debugger Error Error Sep 15, 2025 7:36pm
y-sweet-demos Error Error Sep 15, 2025 7:36pm
y-sweet-gendocs Error Error Sep 15, 2025 7:36pm

@paulgb paulgb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I think TCP does something similar already so I'm not sure if this is the problem, but it doesn't hurt and should at least give us some better insight into when a connection is dropped because of missed heartbeat.

@rolyatmax

Copy link
Copy Markdown
Member Author

LGTM. I think TCP does something similar already so I'm not sure if this is the problem, but it doesn't hurt and should at least give us some better insight into when a connection is dropped because of missed heartbeat.

@paulgb yeah, TCP does, but my understanding is that these timeouts can be much longer. According to ChatGPT, Linux will wait for 2 hours of idleness before sending the first probe. This is also configurable though and could be worth setting on our proxies.

@rolyatmax
rolyatmax merged commit dae8947 into main Sep 15, 2025
7 of 10 checks passed
@rolyatmax
rolyatmax deleted the taylor/add-ping-pong-to-websocket-server branch September 15, 2025 19:38
@rolyatmax
rolyatmax requested a review from Copilot September 16, 2025 15:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements WebSocket ping/pong functionality to detect and close zombie connections that may have been lost without proper cleanup. The implementation sends periodic ping messages to clients and monitors for pong responses to determine connection health.

  • Added ping/pong timeout constants with 20-second ping intervals and 40-second pong timeouts
  • Modified the WebSocket message sending loop to include periodic ping messages with timeout detection
  • Added pong message handling to update the last received pong timestamp

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread crates/y-sweet/src/server.rs
Comment thread crates/y-sweet/src/server.rs
abyssparanoia added a commit to arcterus-jp/y-sweet that referenced this pull request Feb 4, 2026
* derive Deserialize for ClientToken (jamsocket#403)

makes it easier to consume the ClientToken for other rust libraries

* Add support for Y_SWEET_MAX_BODY_SIZE (jamsocket#405)

This PR adds support for `Y_SWEET_MAX_BODY_SIZE` environment variable to
override the default axum websocket body size of 2MB

* better websocket URL generation (jamsocket#406)

* v0.9.0 (jamsocket#408)

* add websocket pings/pongs to help close zombie connections (jamsocket#410)

* fix some websocket server issues (jamsocket#411)

One of these fixes an issue I introduced in my last PR. The other is
pre-existing.

* v0.9.1 (jamsocket#412)

* Allow pycrdt up to and including 0.12.x (jamsocket#414)

Fixes jamsocket#400

Tested locally:

```
uv run pytest
......                                                                                                                                 [100%]
6 passed in 20.34s
```

* only persist documents to S3 when dirty (jamsocket#416)

Fix an issue where y-sweet was persisting documents to S3 every ~10
seconds even when no changes had occurred.

From what I understand, the persistence worker wakes up both on the
dirty signal and also on a `checkpoint_freq` interval and was always
calling persist, regardless of the dirtiness, which would write it to S3
regardless of whether any changes had been made.

The fix adds a check to only persist when the document is actually
dirty.

I'm still a little bit unclear behind the reasoning for the logic of
signaling the worker both on a dirty callback and on a timer.

So I wonder if we instead just start the worker once, wake every 10
seconds, check if dirty, persist if needed.

* use SeqCst ordering for sync_kv dirty flag (jamsocket#417)

Now that [we're not persisting unless the document is marked
dirty](jamsocket#416), let's use an
atomic ordering with stronger guarantees for the KV store's `dirty`
flag.

* Allow to disable GC within documents using env variable/CLI (jamsocket#422)

### References

- closes jamsocket#421 

### Description

Adds an option to disable GC within documents (distinct from GC of
documents in multi-document mode) via:
- CLI by passing `--skip-gc` to either of `y-sweet serve` or `y-sweet
serve-doc`
- `Y_SWEET_SKIP_GC` environment variable

I was not sure if I should also add the environment variable to
`y-sweet-worker` for feature parity but given that it is deprecated I
went for a smaller changeset and only added it in the server.

I wonder if the configuration for toggling GC of documents themselves
(the `doc_gc` option which is not exposed by clap) would be advisable,
but I think it is already possible to configure
`checkpoint_freq_seconds` instead which can be set to a very high value
that is probably better than turning it off altogether.

* feat: divide before main stream

* fix: lint

---------

Co-authored-by: Theodor Tonum <theodor@tonum.no>
Co-authored-by: Vinay M <rmdort@gmail.com>
Co-authored-by: Taylor Baldwin <taylorbaldwin@gmail.com>
Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
Co-authored-by: Aleksey Smolenchuk <lxe@lxe.co>
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.

3 participants