Skip to content

feat: per-connection observability added (#212)#214

Merged
hoytech merged 1 commit intohoytech:masterfrom
archief2910:feature/212-outbound-bytes-per-relay
Apr 22, 2026
Merged

feat: per-connection observability added (#212)#214
hoytech merged 1 commit intohoytech:masterfrom
archief2910:feature/212-outbound-bytes-per-relay

Conversation

@archief2910
Copy link
Copy Markdown
Contributor

Description

This PR adds per-connection observability for outbound payload still inside uWebSockets on the relay WebSocket server.

src/apps/relay/RelayWebsocket.cpp

  • Extends Connection::Stats with pendingOutbound: application bytes passed to WebSocket::send that are not yet fully drained (still in uWS’s queue or an in-flight partial write).
  • In doSend, increments pendingOutbound by payload.size() immediately before send(), passes that size through the send completion callback’s user-data pointer (uintptr_t via void *), and decrements in the callback when uWS reports the message finished (success, immediate failure, or after queued drain).
  • The completion callback returns early when ws == nullptr, matching uWS’s onEnd flush path: that runs after onDisconnection has logged and deleted the Connection, so we must not dereference getUserData() there. The disconnect log therefore captures whatever pendingOutbound was at teardown time; post-disconnect cancellation callbacks do not touch freed memory.
  • Extends the existing disconnect log line (UP/DN bytes and compression) with Pending: … using the same renderSize helper.

No change to when or what is sent; no new config; no back-pressure or connection termination (follow-up work).

Related Issue

Closes #212

Motivation and Context

Slow or stalled readers can leave a large amount of application payload buffered inside uWS. Today operators see aggregate UP bytes on disconnect but not how much was still queued at disconnect. This change makes that visible per connection so memory pressure and slow peers are easier to correlate, without claiming full TCP buffer accounting.

How Has This Been Tested?

Environment: Local build (e.g. WSL/Linux with existing strfry toolchain per README).

Commands run:

  • make -j4 (or project-equivalent full relay build)
  • Manual smoke: ./strfry relay, WebSocket client connect → REQ path that receives outbound frames → clean close; confirm disconnect log includes Pending: (e.g. 0b when the queue has drained before close).

Automated tests: None added; there is no existing unit/integration target in this repo for RelayWebsocket / uWS in test/. (If you add one before opening the PR, update this section.)

Screenshots (if appropriate): N/A

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • I have updated the TODO accordingly.
  • All new and existing tests passed (build + manual smoke; adjust if you run a CI suite).

@archief2910
Copy link
Copy Markdown
Contributor Author

archief2910 commented Apr 19, 2026

hi @hoytech , can you please review it once as this would be blocker for the second issue related to the back pressure work.

@archief2910
Copy link
Copy Markdown
Contributor Author

Hi @hoytech , just a gentle follow-up on this PR. This is currently blocking the next issue related to back-pressure, so a review when you have time would really help. Happy to make any changes if needed.

Copy link
Copy Markdown
Owner

@hoytech hoytech left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

@hoytech hoytech merged commit 24b1b79 into hoytech:master Apr 22, 2026
1 check 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.

Feature : Track pending outbound bytes per relay WebSocket connection

2 participants