Skip to content

Throttle repeated packet-parse error logs in FullPacketParser - #179

Open
u9g wants to merge 1 commit into
ProtoDef-io:masterfrom
u9g:ratelimit-partial-read
Open

Throttle repeated packet-parse error logs in FullPacketParser#179
u9g wants to merge 1 commit into
ProtoDef-io:masterfrom
u9g:ratelimit-partial-read

Conversation

@u9g

@u9g u9g commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Problem

When a stream is malformed or version-mismatched, the same packet can fail to parse on every frame the server sends. FullPacketParser._transform logged the full stack on each PartialReadError, so one persistent fault produced thousands of identical stacks a minute and drowned every other log line. A real session was seen emitting ~15,000 identical Read error for undefined : undefined stacks — tens of megabytes — over ~45 minutes.

Change

A small per-instance throttle: each distinct error (keyed on the top line of its stack) is logged in full on its first occurrence, then again only at the 1st, 2nd, 4th, 8th, … occurrence with a repeat count. A persistent fault costs O(log n) lines instead of n, while the first full stack — the part you actually diagnose from — is always kept, and distinct faults are still each reported. The same throttle is applied to the chunk-size-mismatch log two lines up, which is the same failure family.

noErrorLogging still suppresses everything, unchanged.

Testing

  • 1,000 identical partial-read errors → 10 log lines (n = 1, 2, 4, … 512); two interleaved signatures × 4 each → 6 lines (each hits 1, 2, 4).
  • npm test — all 501 existing tests pass; parser semantics unchanged.

A malformed or mismatched stream can make the same packet fail to parse on
every frame it sends. FullPacketParser logged the full stack each time, so
one persistent fault produced thousands of identical stacks a minute and
buried every other log line -- a single session was seen writing ~15k
identical PartialReadError stacks, tens of megabytes.

Each distinct error (keyed on the top of its stack) is now logged in full
on its first occurrence, then only at the 1st, 2nd, 4th, 8th, ... with a
repeat count, so a persistent fault costs O(log n) lines instead of n. The
same throttle covers the chunk-size-mismatch log two lines up. Counts are
per parser instance; noErrorLogging still silences everything.
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