Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JS API deserializer #709

Merged
merged 5 commits into from
Jan 13, 2025
Merged

Fix JS API deserializer #709

merged 5 commits into from
Jan 13, 2025

Conversation

mtmk
Copy link
Collaborator

@mtmk mtmk commented Jan 12, 2025

Fixes a serialization issue that was happening when interacting with JetStream APIs. Impact should be minimal since JetStream API calls would be retried in most cases however you might see warnings in your logs regarding malformed JSON buffers. The bug was introduced in v2.5.5.

Basically JsonDocument was handed a buffer which it accesses after the point where buffer is returned to the pool and overwritten with new data, while JsonDocument still reading it and causing JSON serialization exceptions.

Solution was to confine serialization with in the serializer and return an optional type NatsJSApiResult<T> representing an API error type or the requested type.

mtmk added 5 commits January 12, 2025 14:58
Replace JsonDocument-based responses with strongly-typed `NatsJSApiResult<T>`
for improved type safety and error handling. Added new deserialization logic
and tests to cover valid responses, errors, and edge cases like empty buffers.
@mtmk mtmk marked this pull request as ready for review January 13, 2025 12:23
@mtmk mtmk requested a review from scottf January 13, 2025 12:23
@mtmk mtmk added bug Something isn't working bug fix and removed bug Something isn't working labels Jan 13, 2025
Copy link
Contributor

@scottf scottf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mtmk mtmk merged commit 6bf76e2 into main Jan 13, 2025
13 checks passed
@mtmk mtmk deleted the fix-js-api-deserializer branch January 13, 2025 14:46
mtmk added a commit that referenced this pull request Jan 13, 2025
* Fix JS API deserializer (#709)
@mtmk mtmk mentioned this pull request Jan 13, 2025
mtmk added a commit that referenced this pull request Jan 13, 2025
* Fix JS API deserializer (#709)
@mtmk mtmk added this to the v2.5.6 milestone Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants