Repository navigation
Conversation
Cloudflare's edge negotiates permessage-deflate with URLSession, which checks maximumMessageSize against the compressed message. Encrypted frames don't compress, so a full 65,535-byte Noise frame (every chunk of a long thread's snapshot) arrived a few bytes over the limit and the receive failed with EMSGSIZE (NSPOSIXErrorDomain 40), dropping the relay channel within seconds of every welcome. Give the socket 4 KiB of headroom; the Noise layer still refuses any frame past 65,535 bytes once it is read. Co-Authored-By: spade <bot@acehq.dev>
…5 bytes The phone's relay socket sizes its receive limit from this bound. Co-Authored-By: spade <bot@acehq.dev>
A hello may carry lastClose: the code, the client's own reason, whether it was ready and for how long, and how long it was down. Through a relay the daemon only learns "Peer closed", so this puts the far side's reason in ace.jsonl. A report that doesn't parse is dropped, never the hello, and older daemons ignore the field. Co-Authored-By: spade <bot@acehq.dev>
The main socket's hello after a drop reports it, until a welcome settles it. Co-Authored-By: spade <bot@acehq.dev>
Co-Authored-By: spade <bot@acehq.dev>
The generator can't state a .catch in JSON Schema, so the field says what it reads and why a bad report never refuses the hello. Co-Authored-By: spade <bot@acehq.dev>
The hello's lastClose carried the client's free-form reason, and the daemon's log kept such text verbatim. It now carries a cause from a fixed list (emsgsize, receive_failed, send_failed, handshake_timeout, heartbeat, peer_closed, other) beside its numbers. The SDK reads a cause from a missed heartbeat or a native socket's `relay:<cause>` reason, and anything unknown is `other`; the daemon's schema strips any other field. Co-Authored-By: spade <bot@acehq.dev>
…rts them A receive the socket refused as too large closes as `1006 relay:emsgsize` (also when the task ends before its receive callback says so); other receive and send failures and a handshake timeout name their own cause. Closes without a nameable cause keep the bare code. Co-Authored-By: spade <bot@acehq.dev>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why the iPhone kept dropping over ace's relay
Every relayed channel from the phone ended a few seconds after its welcome. The phone's log said why, once per drop:
POSIX 40 is EMSGSIZE.
RelaySocketsetmaximumMessageSizeto exactly 65,535, the largest relay frame. Cloudflare's edge negotiates permessage-deflate with URLSession, and URLSession checks the limit against the message as it arrives, compressed. Encrypted frames don't compress, so a full 65,535-byte frame arrives a few bytes larger and the receive fails. Full frames appear as soon as a message is longer than one chunk, such as a long thread's snapshot. So each reconnect died while loading the thread, the backoff never reset, and long threads stayed on the skeleton.I reproduced it on a Mac with a URLSession socket and a deflating peer:
NSPOSIXErrorDomain 40On the daemon's side:
1000 Peer closedwas the relay reporting that the phone went away.1006 Socket closedwas the same event, seen while the daemon was mid-send.Changes
RelaySockettakes up to 65,535 + 4,096 bytes per received message. The Noise layer still refuses any frame over 65,535 once it is read. This is the change confirmed live on the owner's phone: 0 drops in 8+ minutes, down from one every 1–5 s.lastClose: the code, its reason, whether it was ready, how long it had been up and down, and the attempt number. The daemon logs it asClient's last connection closednext to its own close record, so the next drop can be explained fromace.jsonl. A report that doesn't parse is dropped and the hello is still welcomed. Older daemons ignore the field.Backoff needed no change. It resets once a connection stays up for
healthyMs(reconnect-backoff.test.ts); it kept climbing only because no connection lasted that long.Tests
apps/ios/Tests/RelayMessageLimitTests.swift: the daemon side seals a 1.1 MB message into full-size frames, a loopback WebSocket peer sends them permessage-deflated, and a task prepared byRelaySocketreceives and reassembles them. With the old limit it fails with EMSGSIZE.apps/relay/src/relay.process.test.ts: the frame bound.packages/client/src/close-report.test.tsandapps/daemon/src/socket-close-log.server.process.test.ts: the report is sent, settled by a welcome, logged, and a malformed one is ignored.Closes #1876