Skip to content

[AI-8th] Sync Recycler improvements from Netty to fix memory leak#1264

Open
lucianaib0318 wants to merge 1 commit intosofastack:masterfrom
lucianaib0318:ai-8th-recycler-fix
Open

[AI-8th] Sync Recycler improvements from Netty to fix memory leak#1264
lucianaib0318 wants to merge 1 commit intosofastack:masterfrom
lucianaib0318:ai-8th-recycler-fix

Conversation

@lucianaib0318
Copy link
Copy Markdown

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.

Closes sofastack#1240

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +98 to +99
private static int safeFindNextPositivePowerOfTwo(int value) {
return value <= 0 || value >= 1073741824 ? 1073741824 : Integer.highestOneBit(value) << 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Sync Recycler improvements from Netty to fix memory leak

1 participant