Skip to content

fix(lib): give each thread its own VCDiffDecoder - #1240

Merged
ttypic merged 1 commit into
ably:mainfrom
xwang1498:fix/vcdiff-decoder-thread-safety
Sep 15, 2026
Merged

ttypic merged 1 commit into
ably:mainfrom
xwang1498:fix/vcdiff-decoder-thread-safety

Conversation

@xwang1498

@xwang1498 xwang1498 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

The shared static decoder keeps per-decode state, so two channels decoding on different threads at the same time were corrupting each other's deltas (40018, then a re-attach). Use a ThreadLocal instead.

Use older syntax for backwards compatibility.

I can add tests if you'd like, but it felt like a lot of ceremony to verify a pretty clear fix.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when processing compressed messages concurrently by providing each thread with its own decoder instance.

The shared static decoder keeps per-decode state, so two channels decoding on
different threads at the same time corrupt each other's deltas (40018, then a
re-attach). Use a ThreadLocal instead.
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f96dd6f4-5d1f-408d-855f-b6af8a08ed87

📥 Commits

Reviewing files that changed from the base of the PR and between 243a08c and 34350cb.

📒 Files selected for processing (1)
  • lib/src/main/java/io/ably/lib/types/BaseMessage.java

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

BaseMessage now stores VCDiffDecoder in a ThreadLocal. Each thread lazily receives its own decoder, and vcdiffApply uses that decoder for decoding.

Changes

Thread-local VCDiff decoding

Layer / File(s) Summary
Decoder initialization and use
lib/src/main/java/io/ably/lib/types/BaseMessage.java
vcdiffDecoder is now a thread-local value with lazy initialization. vcdiffApply retrieves the decoder with get() before decoding.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 34350

The decoder isolation change preserves recovery behavior, and no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: assigning each thread its own VCDiffDecoder.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the decoder thread by thread
Each gets its own path where VCDiff is led
Lazy ears wake when decoding begins
No shared state tangles the spins
BaseMessage hops onward, neatly fed

Comment @coderabbitai help to get the list of available commands.

@sacOO7
sacOO7 requested review from ttypic and a lite review from Copilot September 14, 2026 13:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request isolates VCDIFF decoder state per thread to prevent concurrent decoding corruption.

Changes:

  • Replaces the shared decoder with a ThreadLocal decoder.
  • Preserves older syntax for compatibility.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/src/main/java/io/ably/lib/types/BaseMessage.java

@ttypic ttypic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for contribution

@ttypic
ttypic merged commit 71b14b8 into ably:main Sep 15, 2026
12 of 15 checks passed
@xwang1498
xwang1498 deleted the fix/vcdiff-decoder-thread-safety branch September 15, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants