Skip to content

Conversation

@ejona86
Copy link
Member

@ejona86 ejona86 commented Mar 31, 2017

d116cc9 fixed the NPE, but the initialization of the manager happened
after newHandler() was called, so a null manager was passed to the
handler.

Fixes #2828


I haven't tested this manually yet. I wanted to send it out to get opinions on whether this is the fix we want. It seems considerably less invasive than some other options we were discussing.

d116cc9 fixed the NPE, but the initialization of the manager happened
_after_ newHandler() was called, so a null manager was passed to the
handler.

Fixes grpc#2828
@SuppressWarnings("unchecked")
@Override
public Runnable start(Listener transportListener) {
lifecycleManager = new ClientTransportLifecycleManager(
Copy link
Contributor

Choose a reason for hiding this comment

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

did you forget to replace the lifecycleManager field with a local variable? Ditto for the keepaliveManager field if it is not exposed to test.

Copy link
Member Author

Choose a reason for hiding this comment

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

lifecycleManager is used in statusFromFailedFuture, so it must remain a field. I left keepaliveManager because it is used by the test... although I agree that is questionable given the test didn't catch this bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

oops, I see lifecycleManager is also used in statusFromFailedFuture. But why did you add lifecycleManager as an extra argument of newHandler?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought my comment explained that:

Only use fields initialized before start()

Since lifecycleManager is initialized in start(), the flow in start() is more obvious when being passed as an argument. Otherwise you could move newHandler() within start() and not notice that a field is no longer initialized.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I think move it inside start() is cleaner since it's only one line of code and used only once.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I think move it inside start() is cleaner since it's only one line of code and used only once.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Done.

Copy link
Contributor

@dapengzhang0 dapengzhang0 left a comment

Choose a reason for hiding this comment

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

The fix looks very nice!

@ejona86
Copy link
Member Author

ejona86 commented Apr 1, 2017

I've run manual tests and I see keepalive pings!

@ejona86 ejona86 merged commit f9eb545 into grpc:master Apr 1, 2017
@ejona86 ejona86 deleted the fix-netty-client-keepalive branch April 1, 2017 00:21
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeepAliveManager is not apply to ConnectionHandler in netty transport

2 participants