-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix pulsar service close exception #8197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix pulsar service close exception #8197
Conversation
@@ -215,7 +215,9 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { | |||
super.channelInactive(ctx); | |||
isActive = false; | |||
log.info("Closed connection from {}", remoteAddress); | |||
getBrokerService().getInterceptor().onConnectionClosed(this); | |||
if (getBrokerService().getInterceptor() != null) { | |||
getBrokerService().getInterceptor().onConnectionClosed(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In BrokerService we are setting this field to null.
We could run into some NPE anyway in the future.
It is better to assign the result of getInterceptor to a local variable and then deference it safely, without calling twice this getter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eolivelli Thanks for your feedback. I will use the a local variable to avoid calling twice of getInterceptor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/pulsarbot run-failure-checks |
Fix #8196 ### Motivation In BrokerService#close, it close interceptor first and close workerGroup in the second. However, in workerGroup.shutdownGracefully(), it will call ServerCnx#channelInactive method. The code with bug as follow. ``` getBrokerService().getInterceptor().onConnectionClosed(this); ``` It doesn't check whether `getBrokerService().getInterceptor()` is null and call `onConnectionClosed` may cause NullPointerException. ### Changes 1. In BrokerService#close, close workerGroup first and close interceptor in the second. 2. In ServerCnx#channelInactive, check `getBrokerService().getInterceptor()` whether is null before call onConnectionClosed method. (cherry picked from commit 01cd0bc)
Fix apache#8196 ### Motivation In BrokerService#close, it close interceptor first and close workerGroup in the second. However, in workerGroup.shutdownGracefully(), it will call ServerCnx#channelInactive method. The code with bug as follow. ``` getBrokerService().getInterceptor().onConnectionClosed(this); ``` It doesn't check whether `getBrokerService().getInterceptor()` is null and call `onConnectionClosed` may cause NullPointerException. ### Changes 1. In BrokerService#close, close workerGroup first and close interceptor in the second. 2. In ServerCnx#channelInactive, check `getBrokerService().getInterceptor()` whether is null before call onConnectionClosed method.
Fix #8196
Motivation
In BrokerService#close, it close interceptor first and close workerGroup in the second. However, in workerGroup.shutdownGracefully(), it will call ServerCnx#channelInactive method. The code with bug as follow.
It doesn't check whether
getBrokerService().getInterceptor()
is null and callonConnectionClosed
may cause NullPointerException.Changes
getBrokerService().getInterceptor()
whether is null before call onConnectionClosed method.