Skip to content

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

Merged
chrisvest merged 1 commit into
4.1from
t_leak41
Jun 19, 2026
Merged

chrisvest merged 1 commit into
4.1from
t_leak41

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Jun 18, 2026 •

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]>
@chrisvest chrisvest added this to the 4.1.136.Final milestone Jun 19, 2026
@chrisvest
chrisvest merged commit d6be98b into 4.1 Jun 19, 2026
19 checks passed
@chrisvest
chrisvest deleted the t_leak41 branch June 19, 2026 01:06
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…tty#16959) (netty#16976)

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]>

Co-authored-by: skyguard1 <[email protected]>
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.

3 participants