Skip to content

feat(sse): expose last-activity timestamp of the streaming connection - #641

Open
behnam-oneschema wants to merge 1 commit into
splitio:developmentfrom
oneschema:feat/sse-last-activity-timestamp
Open

behnam-oneschema wants to merge 1 commit into
splitio:developmentfrom
oneschema:feat/sse-last-activity-timestamp

Conversation

@behnam-oneschema

Copy link
Copy Markdown

Summary

Applications running the SDK in streaming mode have no way to observe whether the SSE connection is actually alive: :keepalive comments are discarded in process_data, last_synchronizations only moves on a fetch (flag change or reconnect), and the 70 s IO.select read timeout is a local in the read loop. This exposes the liveness signal the client already has.

SSE::EventSource::Client:

# Process::CLOCK_MONOTONIC seconds of the last bytes read from the stream,
# :keepalive comments included. nil when not connected.
def last_activity_at
def seconds_since_last_activity
  • @last_activity_at (Concurrent::AtomicReference) is stamped right after every successful socket.readpartial in connect_stream, before the keepalive filter, and reset to nil inside close's mutex alongside @connected.make_false.
  • Monotonic clock so wall-clock jumps don't produce negative/absurd ages.
  • SSEHandler#last_activity_at / #seconds_since_last_activity delegate to the client (nil-safe).

No behavior change to reconnect/back-off logic; read-only accessors only. Specs cover nil before connect, populated after a keepalive-only stream, and nil after close; plus the handler delegation. CHANGES.txt entry added under an unreleased 8.12.0 heading (version.rb untouched).

Motivation: we surface seconds_since_last_activity as a Prometheus gauge to distinguish a healthy idle stream (age bounded by the server keepalive cadence) from one that's about to hit the 70 s read timeout.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant