fix: bound the number of entries in a compression table advertisement - #3510
Merged
Conversation
Motivation: deserializeCompressionAdvertisement resolves every key in the advertised table, and for actor refs that means parsing a path and populating the resolve cache. The key list was unbounded, so the only limit was the transport frame size. Measured, 10000 entries is 369 KB of wire and about 150 ms of CPU on the inbound control stream, against 9 KB for the 256 entry table a peer legitimately advertises. Modification: Reject an advertisement carrying more entries than pekko.remote.artery.advanced.compression.<table>.max, the setting that bounds the table on the sending side and is normally the same across a cluster. When it is "off" locally there is no number to check against and no bound is applied. Result: An oversized advertisement is reported as a serialization failure, which the inbound stream logs and drops. Advertisements are resent periodically, so a dropped one costs at most a delay in establishing compression.
pjfanning
requested review from
He-Pin,
Philippus,
nvollmar,
raboof and
samueleresca
September 2, 2026 09:38
Member
Author
|
This is a fix that I would like to get into 1.7.1. |
nvollmar
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
deserializeCompressionAdvertisement(ArteryMessageSerializer:179-192) resolves every key inthe advertised table — for actor refs that means
resolveActorRef, which parses a path andpopulates the per-thread resolve cache. The key list was unbounded, so the only limit was the
transport frame size.
Measured on this branch:
256 is what a peer legitimately advertises (
compression.actor-refs.maxdefaults to 256), and9 KB. The default
maximum-frame-sizeof 256 KiB allows roughly 7000 entries, so the reachableworst case is around 100 ms of CPU on the inbound control stream per message, repeatable.
Modification
Reject an advertisement carrying more entries than
pekko.remote.artery.advanced.compression.<table>.max— the setting that bounds the table onthe sending side, parsed here the same way
ArterySettingsparses it. When it is"off"locally the setting is 0, there is no configured number to check against, and no bound is
applied.
The tradeoff worth a reviewer's attention: this bounds by the receiver's setting, but the
table is sized by the sender's. Configurations are normally uniform across a cluster, but
during a rolling change of
actor-refs.maxa node still on the smaller value would reject alarger advertisement. I checked what that costs before choosing it: a
fromBinaryfailure onthe inbound stream is caught at
Codecs.scala:692-704, which logs an error and drops themessage — no quarantine — and
InboundCompressionsresends advertisements periodically(
InboundCompressions.scala:553, "The ActorRefCompressionAdvertisement message is resentbecause it can be lost"). So the worst case for a skewed config is that compression is not
established for that association until both sides are updated; messages still flow uncompressed.
If reviewers would rather have headroom than exactness, the alternative is a separate setting
with a default well above the table maxes.
What I did not change
The review this came from also flagged
ActorRefResolveCacheas hash-floodable:LruBoundedCachenever grows andUnsafe.fastHashis seeded with two fixed public constants,so colliding actor paths can be precomputed offline. I measured it rather than assume:
generating 4096 keys that all land in one slot took 558 ms, and cache operations then went from
2347 ns to 13631 ns, about 5.8x.
That is a real effect but far short of the degradation I expected, the cache is bounded at 1024
entries so nothing grows without limit, and closing it means changing the seed of a public
Unsafe.fastHash. 5.8x on one cache lookup does not seem to justify that, so I left it aloneand am recording the numbers here instead.
Result
An oversized advertisement is reported as a serialization failure. A legitimately sized one is
unaffected.
Tests
sbt "remote/testOnly org.apache.pekko.remote.serialization.*"— 195 passed, 1 pendingOne new test in
ArteryMessageSerializerSpec, checked to discriminate by reverting theproduction file and re-running, where it fails with
no exception was thrown:reject a compression table advertisement with more entries than the configured maximum—asserts a table of exactly
maxentries still deserializes, and thatmax + 1is rejectedsbt "remote/mimaReportBinaryIssues"— no issuessbt "remote/scalafmtCheckAll" headerCreateAll— cleanReferences
Touches the same method as #3507, so whichever merges second needs a trivial rebase; the two
guards are independent.