Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upChannelInitializer may be invoked multiple times when used with custo… #8620
Conversation
This comment has been minimized.
This comment has been minimized.
@atcurtis This should fix your problem |
normanmaurer
requested review from
bryce-anderson
,
ejona86
,
carl-mastrangelo
and
trustin
Dec 4, 2018
normanmaurer
referenced this pull request
Dec 4, 2018
Closed
ChannelInitializer.initChannel() executed more than once when used with context executor #8616
normanmaurer
added this to the 4.1.33.Final milestone
Dec 4, 2018
normanmaurer
added
the
defect
label
Dec 4, 2018
ejona86
reviewed
Dec 4, 2018
initMap.remove(ctx); | ||
// The removal may happen in an async fashion if the EventExecutor we use does something funky. | ||
if (ctx.isRemoved()) { | ||
initMap.remove(ctx); |
This comment has been minimized.
This comment has been minimized.
ejona86
Dec 4, 2018
Member
What's the point of this line? Wouldn't we only get here if handlerRemoved()
was called? Is the concern that someone could override handlerRemoved()
?
This comment has been minimized.
This comment has been minimized.
initMap.remove(ctx); | ||
} else { | ||
// Ensure we always remove from the Map in all cases to not produce a memory leak. | ||
ctx.channel().closeFuture().addListener(new ChannelFutureListener() { |
This comment has been minimized.
This comment has been minimized.
ejona86
Dec 4, 2018
Member
This will retain ctx
until the channel is closed, even if handlerRemoved()
is called. If this is a one-off initializer (not reused) then that could greatly increase the lifetime of some objects used during handshakes and the like.
Is this seriously the only way we can clean up properly? Is the problem that the methods can be overridden? If so, then maybe we should fix that in Netty 5? Or maybe we could avoid the check-for-double-register problem by having an alternative approach to 26aa348 in Netty 5?
It is possible to cancel the future to clean up, but the amount of effort necessary to do something simple makes me question if this is more of systemic problem that should be addressed in Netty 5.
This comment has been minimized.
This comment has been minimized.
normanmaurer
Dec 4, 2018
Author
Member
@ejona86 yeah I think its the best we can do for netty 4 to ensure we not leak if the user overrides handlerRemoved(...)
.Thats also why I check isRemoved()
first.
This comment has been minimized.
This comment has been minimized.
trustin
Dec 5, 2018
Member
Perhaps we could check handlerRemoved() was overridden at instantiation time using reflection and take the fast path?
This comment has been minimized.
This comment has been minimized.
normanmaurer
Dec 5, 2018
Author
Member
@trustin we could ... that said I think it does not really worth it as ctx.isRemoved()
should be true if the EventExecutor
is not some funky custom implemention that is is used with ChannelInitializer
. So I would prefer to keep things simple for now.
This comment has been minimized.
This comment has been minimized.
trustin
approved these changes
Dec 5, 2018
This comment has been minimized.
This comment has been minimized.
You may want to document about this behavior in Javadoc though, e.g. risks of overriding |
This comment has been minimized.
This comment has been minimized.
Good idea
… Am 05.12.2018 um 10:37 schrieb Trustin Lee ***@***.***>:
You may want to document about this behavior in Javadoc though, e.g. risks of overriding handlerRemoved() and using a certain EventExecutor implementation.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
This comment has been minimized.
This comment has been minimized.
@trustin actually I think it is fine to not add docs as the same is true for other methods as well. |
This comment has been minimized.
This comment has been minimized.
@ejona86 any other comment ? |
normanmaurer commentedDec 4, 2018
…m EventExecutor.
Motivation:
The ChannelInitializer may be invoked multipled times when used with a custom EventExecutor as removal operation may be done asynchronously. We need to guard against this.
Modifications:
Result:
Fixes #8616.