Skip to content
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

Merged
merged 3 commits into from
Oct 5, 2020

Conversation

hangc0276
Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hangc0276
Copy link
Contributor Author

/pulsarbot run-failure-checks

@sijie sijie merged commit 01cd0bc into apache:master Oct 5, 2020
wolfstudy pushed a commit that referenced this pull request Oct 30, 2020
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)
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Nov 13, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broker service close with exception
5 participants