Skip to content

expose when data was last received from the websocket client - #53

Merged
bentsku merged 1 commit into
websocket-message-reassemblyfrom
websocket-last-received
Oct 7, 2026
Merged

bentsku merged 1 commit into
websocket-message-reassemblyfrom
websocket-last-received

Conversation

@bentsku

@bentsku bentsku commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

A server that implements an idle timeout has to know when the client was last active. The listener can track the messages it receives, but not the control frames: the twisted channel answers pings itself on the reactor thread, so a client that keeps its connection alive with pings looks idle to the listener.

Changes

  • WebSocketAdapter.last_received_at and WebSocket.last_received_at: the time.monotonic() time at which data was last received from the client, or at which the connection was created if nothing was received yet.
  • twisted: WebSocketChannel updates it on every dataReceived, so pings, pongs and partial frames count too.
  • ASGI: updated when the listener receives a message. ASGI servers don't pass control frames on to the application, so pings can't count there.

Testing

  • New test_last_received_at_message (twisted and asgi): the timestamp after receiving a message must be later than the time the client sent it.
  • New test_last_received_at_ping (twisted): a ping alone must move the timestamp forward.
  • Both twisted tests fail when dataReceived doesn't update the timestamp. The full suite passes (195 tests) and lint is clean.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bentsku
bentsku added this pull request to stack #54 October 7, 2026 00:54
@bentsku
bentsku marked this pull request as ready for review October 7, 2026 09:41
@bentsku
bentsku merged commit 9f84ead into main Oct 7, 2026
10 checks passed
@bentsku
bentsku deleted the websocket-last-received branch October 7, 2026 10:24
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