Skip to content

Correctly release and fail queued traffic-shaping writes on close (#16959) - #16977

Merged
normanmaurer merged 1 commit into
5.0from
t_leak5
Jun 18, 2026
Merged

normanmaurer merged 1 commit into
5.0from
t_leak5

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:
The AbstractTrafficShapingHandler#calculateSize supports ByteBuf,
ByteBufHolder, and FileRegion, so traffic-shaping handlers may queue
delayed ByteBufHolder messages such as HTTP content.
When a channel becomes inactive and queued writes are discarded,
ChannelTrafficShapingHandler, GlobalTrafficShapingHandler, and
GlobalChannelTrafficShapingHandler only release messages that are direct
ByteBuf instances. This leaks queued ByteBufHolder / other
ReferenceCounted messages. The corresponding write promises are also
left incomplete even though the messages will never be written.

Modifications:
• Add a shared queued-write cleanup helper in
AbstractTrafficShapingHandler.
• Use ReferenceCountUtil.safeRelease(...) instead of instanceof ByteBuf
checks.
• Fail discarded queued write promises with ClosedChannelException.
• Reset per-channel queue size after discarded queued writes are cleaned
up.
• Add tests covering queued ByteBufHolder writes for:
◦ ChannelTrafficShapingHandler
◦ GlobalTrafficShapingHandler
◦ GlobalChannelTrafficShapingHandler

Result:
Queued delayed writes are cleaned up consistently when the channel is
closed: reference-counted messages are released and callers waiting on
write promises are notified with failure. Internal queue-size accounting
is left in a clean state on removal.


Co-authored-by: Norman Maurer [email protected]

…6959)

Motivation:
The AbstractTrafficShapingHandler#calculateSize supports ByteBuf,
ByteBufHolder, and FileRegion, so traffic-shaping handlers may queue
delayed ByteBufHolder messages such as HTTP content.
When a channel becomes inactive and queued writes are discarded,
ChannelTrafficShapingHandler, GlobalTrafficShapingHandler, and
GlobalChannelTrafficShapingHandler only release messages that are direct
ByteBuf instances. This leaks queued ByteBufHolder / other
ReferenceCounted messages. The corresponding write promises are also
left incomplete even though the messages will never be written.

Modifications:
• Add a shared queued-write cleanup helper in
AbstractTrafficShapingHandler.
• Use ReferenceCountUtil.safeRelease(...) instead of instanceof ByteBuf
checks.
•	Fail discarded queued write promises with ClosedChannelException.
• Reset per-channel queue size after discarded queued writes are cleaned
up.
•	Add tests covering queued ByteBufHolder writes for:
◦	ChannelTrafficShapingHandler
◦	GlobalTrafficShapingHandler
◦	GlobalChannelTrafficShapingHandler

Result:
Queued delayed writes are cleaned up consistently when the channel is
closed: reference-counted messages are released and callers waiting on
write promises are notified with failure. Internal queue-size accounting
is left in a clean state on removal.

---------

Co-authored-by: Norman Maurer <[email protected]>
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Jun 18, 2026
@normanmaurer
normanmaurer merged commit 29e187d into 5.0 Jun 18, 2026
13 checks passed
@normanmaurer
normanmaurer deleted the t_leak5 branch June 18, 2026 17:58
@normanmaurer normanmaurer mentioned this pull request Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants