sofastack/sofa-jraft

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

オープン

#1,240 opened on 2026/01/11

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)Java (1,125 件のフォーク)batch import
SOFA-8th-Challengedifficulty-mediumgood first issuehelp wanted

Repository metrics

Stars
 (3,406 個のスター)
PR merge metrics
 (平均マージ 20h 13m) (30d で 3 merged PRs)

説明

Motivation

The current Recyclers implementation is forked from an old version of Netty's Recycler. Netty has since made significant improvements, including:

  • PR #11858: Complete rewrite removing WeakOrderQueue
  • PR #9394: Fix reclaimSpace bug
  • PR #11996: Avoid recycling to terminated threads

The current implementation can cause memory leaks in cross-thread scenarios due to unbounded accumulation in WeakOrderQueue.

Modification

Sync the Recycler implementation from Netty 4.1.69+, which:

  • Removes WeakOrderQueue entirely
  • Uses simple MPSC queue for thread-local pooling
  • Eliminates cross-thread memory leak issues

Result

Memory leak in Recyclers is fundamentally fixed.

Netty Recycler change history

40196a6305 Rewrite and simplify Recycler (#11858) -- 2021-11-26 ⭐ 55cdaa75ad Try to not recycle objects back to terminated threads (#11996) -- 2021-12-14 98a3a0c0cb Recycler.WeakOrderQueue drop Object hasBeenRecycled (#11402) dde82f62f0 Fix bug in Recycler with racing calls to recycle (#11037) 909e7c9c29 Add option to configure recycler delayed queue drop ratio (#10251) 94f3930850 Recycler availableSharedCapacity slowly exhausted (#9394) -- 2019-07-22 6cd5e8b0ca Reduce default capacity from 32k to 4k -- 2018-02-09

コントリビューターガイド