sofastack/sofa-jraft

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

开放

#1,240 创建于 2026年1月11日

 (1 条评论) (0 个反应) (0 位负责人)Java (1,125 个派生)batch import
SOFA-8th-Challengedifficulty-mediumgood first issuehelp wanted

仓库指标

星标
 (3,406 个星标)
PR 合并指标
 (平均合并 20小时 13分钟) (30 天内合并 3 个 PR)

描述

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

贡献者指南