Conversation
gvdutra
marked this pull request as draft
September 7, 2026 01:33
Contributor
|
Just to let you know I've seen this. It would be very expensive to ensure a deep copy. There is no contract that says a header is reusable, this is a known limitation. |
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.
Copying
Headersand appending a value for an existing key can prevent subsequent messages from being delivered. The copy constructor copies the map but shares its mutable value lists. Updating either instance changes both sets of values, while only updating one instance's length bookkeeping.This affects applications that copy a reusable header template and extend it for an individual message. It also allows changes to the source to alter a read-only copy.
Reproduction
With a connected
Connection ncand a running NATS server:Expected: both messages arrive with the original payload; the first has
Trace: base, and the second has bothbaseandderivedvalues.Before the fix, extending the copy also changes
template, leaving its recorded header length too small. The client reportsIllegalArgumentException: Invalid header composition, andfirstisnull. This was reproduced against a real NATS server onmainatf83ba05d.Change
Copy each value list in the
Headerscopy constructor so the source and destination have independent mutable state. Preserve the existing map sizing, length bookkeeping, read-only flag, and excluded-key handling.Regression coverage checks:
Validation
All four new regression cases fail without the fix. With the fix, all 61 tests in the targeted suites pass, with no failures or skips:
Tested with Temurin JDK 21.0.11 and NATS Server 2.14.6 on macOS arm64.
git diff --checkpasses. The full test suite was not run.