sofastack/sofa-jraft

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

Open

#1.240 aberto em 11 de jan. de 2026

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)Java (1.125 forks)batch import
SOFA-8th-Challengedifficulty-mediumgood first issuehelp wanted

Métricas do repositório

Stars
 (3.406 stars)
Métricas de merge de PR
 (Mesclagem média 20h 13m) (3 fundiu PRs em 30d)

Description

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

Guia do colaborador