Skip to content

fix: use a Seq rather than a Set to hold TCP magic ByteStrings (#3484) - #3498

Open
pjfanning wants to merge 1 commit into
apache:1.7.xfrom
pjfanning:magic-1.7
Open

fix: use a Seq rather than a Set to hold TCP magic ByteStrings (#3484)#3498
pjfanning wants to merge 1 commit into
apache:1.7.xfrom
pjfanning:magic-1.7

Conversation

@pjfanning

Copy link
Copy Markdown
Member

cherry pick 43695a7 #3484

Adjusted the test expectations to match the default order of the AKKA and PEKK values in the 1.7.x branch

…e#3484)

Motivation:
default to HashSet, which hashes its members, and hashing a ByteString walks
every one of its bytes. Comparing this handful of 4-byte values is better done
with a couple of equality checks over a small ordered collection.

Modification:
Change ArterySettings.Advanced.TcpMagicValues from Set[ByteString] to
immutable.Seq[ByteString], built with distinct.toList rather than toSet so the
de-duplication the Set provided incidentally is kept, and change the
TcpFraming acceptedMagic parameter to match. These were the only two
Set[ByteString] in the tree; both are private[pekko] and both arrived in apache#3425.

Add ArterySettingsSpec, which did not exist: the tcp-magic parsing added by

Result:
TcpFraming's magic check on each inbound connection is a small number of
ByteString equality comparisons instead of a hashCode over the received bytes.
Acceptance order is now the configured order, where the Set left it
unspecified; this is consistent with TcpMagic, the outbound magic, already
being the first configured value. No other behaviour changes.

Tests:
- sbt "remote/testOnly org.apache.pekko.remote.artery.ArterySettingsSpec" - 7
  tests succeeded, 0 failed
- sbt "remote/testOnly org.apache.pekko.remote.artery.tcp.TcpFramingSpec" - 11
  tests succeeded, 0 failed, covering the default, custom and legacy AKKA magic
  paths through the changed contains call
- sbt "remote/mimaReportBinaryIssues" - no issues, no filters needed
- ArterySettingsSpec pins the configuration order, the de-duplication including
  after 4-byte truncation, and both require rejections, so the collection type
  cannot be changed back without a failure.

References:
Fixes apache#3483, Refs apache#3425

Update TcpFramingSpec.scala

Update ArterySettingsSpec.scala
@pjfanning
pjfanning marked this pull request as draft August 31, 2026 09:13
@pjfanning pjfanning added this to the 1.7.1 milestone Aug 31, 2026
@pjfanning
pjfanning marked this pull request as ready for review August 31, 2026 11:34
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