Skip to content

fix: throttle PROVIDERSTATUS server events - #2974

Open
dirkwa wants to merge 1 commit into
SignalK:masterfrom
dirkwa:fix-providerstatus-throttle
Open

fix: throttle PROVIDERSTATUS server events#2974
dirkwa wants to merge 1 commit into
SignalK:masterfrom
dirkwa:fix-providerstatus-throttle

Conversation

@dirkwa

@dirkwa dirkwa commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

setPluginStatus / setProviderStatus emit a PROVIDERSTATUS server event carrying the full provider status list on every call. A plugin that calls it in a loop turns that into a continuous stream on every admin-UI WebSocket — in #2972 ~2.4 MB/s, 196 MB queued on one socket before the overflow cut it — and everything else on that socket, including the Data Browser's own subscription data, waits behind the backlog.

This coalesces status changes into at most one PROVIDERSTATUS emit per second — the first change goes out immediately, further changes within the second fold into one emit when it expires — so a chatty caller is bounded at ~8 KB/s per client while the admin UI still shows the latest status within a second. The 5-second periodic full refresh is unchanged; a pending emit is cancelled on stop().

Fixes #2972

Tested

  • npm run format, npm run build:all, npm test (server suite 1236 passing, workspaces green, ci-lint clean)
  • New unit test test/providerStatusEmitter.ts: a burst of 1000 requests → one prompt emit and one more when the interval expires, prompt emit after a quiet interval, emitNow and cancel drop a pending request
  • Measured on a live 2.31 install: with the unthrottled path a single admin socket accumulated 12.8 MB in 11 s and 196 MB in 87 s (bug-report bundle in Bug report 20260816T183202Z #2972); the same server code with a well-behaved plugin set idles at 0.4 PROVIDERSTATUS/s

Summary

This PR throttles PROVIDERSTATUS events to one emission per second. The first status change emits immediately. Subsequent changes are coalesced into one trailing emission.

The existing five-second full refresh remains unchanged. Pending emissions are canceled during stop().

ProviderStatusEmitter centralizes throttling behavior. Tests cover burst coalescing, delayed emissions, emitNow, and cancellation.

This reduces WebSocket backlog from chatty plugins and improves Data Browser response time.

setPluginStatus/setProviderStatus emitted the full provider status
list on every call. A plugin calling it in a loop pushes megabytes
per second into every admin-UI WebSocket; the socket buffers grow
until the connection is cut and the Data Browser's own subscription
data queues behind the backlog (SignalK#2972: 196 MB on one socket, ~2.4
MB/s).

Coalesce calls into at most one PROVIDERSTATUS emit per second,
trailing edge, so the admin UI still sees the latest status promptly
while a chatty caller can no longer flood the socket. The 5-second
periodic full refresh is unchanged.
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c326bf05-6420-4772-a7f3-7a41e2a74379

📥 Commits

Reviewing files that changed from the base of the PR and between 135e68a and 4448d4c.

📒 Files selected for processing (3)
  • src/index.ts
  • src/providerStatusEmitter.ts
  • test/providerStatusEmitter.ts

Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Provider-status events now pass through a throttling emitter. Burst updates are coalesced, status is refreshed every five seconds, immediate emissions remain available, and pending emissions are canceled during shutdown.

Changes

Provider status event lifecycle

Layer / File(s) Summary
Emitter behavior and validation
src/providerStatusEmitter.ts, test/providerStatusEmitter.ts
Added configurable request coalescing, immediate emission, timer cancellation, unreferenced timers, and asynchronous tests for burst, interval, immediate, and canceled emissions.
Server integration and lifecycle
src/index.ts
Server provider-status updates now request emission through ProviderStatusEmitter. A five-second refresh calls emitNow(), and shutdown calls cancel().

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 4448d

The change bounds PROVIDERSTATUS event delivery while preserving prompt updates and periodic refresh behavior; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Server
  participant ProviderStatusEmitter
  participant PROVIDERSTATUS listeners
  Server->>ProviderStatusEmitter: request() after provider-status update
  ProviderStatusEmitter->>PROVIDERSTATUS listeners: emit coalesced status
  Server->>ProviderStatusEmitter: emitNow() every five seconds
  Server->>ProviderStatusEmitter: cancel() during shutdown
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: throttling PROVIDERSTATUS server events.
Description check ✅ Passed The description explains the user-facing problem, the solution, measured impact, testing, and the linked issue.
Linked Issues check ✅ Passed The changes address the Data Browser delay in [#2972] by reducing PROVIDERSTATUS WebSocket backlog through coalescing and throttling.
Out of Scope Changes check ✅ Passed The implementation and tests are limited to PROVIDERSTATUS emission throttling, periodic refresh handling, shutdown cancellation, and related behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dirkwa

dirkwa commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

ready for human review


export const PROVIDER_STATUS_MIN_INTERVAL_MS = 1000

export class ProviderStatusEmitter {

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.

this is not a ProviderStatusEmitter - it does not emit provider statuses, but is used to emit them. to me it is ThrottledCaller - it calls the given function but throttles the calls as described. imho naming should reflect that and min interval come from callee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report 20260816T183202Z

2 participants