[AI-8th] Sync Recycler improvements from Netty to fix memory leak#1264
[AI-8th] Sync Recycler improvements from Netty to fix memory leak#1264lucianaib0318 wants to merge 1 commit intosofastack:masterfrom
Conversation
Closes sofastack#1240 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6bb65cbf97
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| queue.add(this); | ||
| public boolean compareAndSetLastRecycledId(int expectLastRecycledId, int updateLastRecycledId) { | ||
| return LAST_RECYCLED_ID_UPDATER.weakCompareAndSet(this, expectLastRecycledId, updateLastRecycledId); |
There was a problem hiding this comment.
Replace weak CAS with strong CAS for recycled-id updates
compareAndSetLastRecycledId uses weakCompareAndSet, which is allowed to fail spuriously even when the expected value matches; this makes valid recycle paths nondeterministically fail. In pushNow that spurious failure is treated as a hard duplicate-recycle error and throws IllegalStateException, and in cross-thread queueing it can silently drop recyclable handles. Use a strong compareAndSet (or retry loop) so only real races are rejected.
Useful? React with 👍 / 👎.
| private static int safeFindNextPositivePowerOfTwo(int value) { | ||
| return value <= 0 || value >= 1073741824 ? 1073741824 : Integer.highestOneBit(value) << 1; |
There was a problem hiding this comment.
Fix power-of-two helper to preserve exact powers of two
safeFindNextPositivePowerOfTwo currently returns highestOneBit(value) << 1, which doubles values that are already powers of two (for example, configured/default 16 becomes 32). Because LINK_CAPACITY is derived from this method, users cannot actually set a power-of-two link size as requested, and default memory usage per link is inflated unexpectedly.
Useful? React with 👍 / 👎.
Closes #1240
Motivation:
Explain the context, and why you're making that change.
To make others understand what is the problem you're trying to solve.
Modification:
Describe the idea and modifications you've done.
Result:
Fixes #.
If there is no issue then describe the changes introduced by this PR.