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

Executor usage in ClientCallImpl races with channel shutdown and termination. #1981

Open
zhangkun83 opened this issue Jun 25, 2016 · 4 comments
Assignees
Labels
Milestone

Comments

@zhangkun83
Copy link
Contributor

ManagedChannelImpl clear scheduledExecutor in shutdown(), and releases (which potentially closes) executor in maybeTerminateChannel().

Neither newCall() nor ClientCallImpl checks the shutdown state of the channel. ClientCallImpl relies on FailingClientTransport for the expected behavior. However, ClientCallImpl uses the passed in executors anyway, for scheduling the deadline timer and invoking the call listener.

If ClientCallImpl tries to schedule a deadline timer after the channel is shut down, it will get a NPE. If it runs the call listener after the shared executor has been closed, which is 1 second (SharedResourceHolder.DESTROY_DELAY_SECONDS) after all references are gone, e.g., the application calls Call.start() that late, it will get a RejectedExecutionException. Our current tests are not testing for the two cases.

This doesn't seem to be a serious issue. It only affect people who try to use Calls after the channel has been shutdown. I am yet to figure out a solution.

Anyway, it seems executor should be cleared after being returned to the shared pool, like scheduledExecutor.

@ejona86 ejona86 added the bug label Aug 22, 2016
@ejona86 ejona86 added this to the 1.1 milestone Aug 22, 2016
@zhangkun83
Copy link
Contributor Author

We should not miss out the case where a new call is created, the channel is terminated, then the call is started. Simply resetting the executors in channel upon termination doesn't help with this case, because the call holds on to the executors.

@zhangkun83
Copy link
Contributor Author

OobChannel has the same issue with ManagedChannelImpl.

@zhangkun83 zhangkun83 changed the title Executor usage in newCall() races with channel shutdown and termination. Executor usage in ClientCallImpl races with channel shutdown and termination. Dec 29, 2016
@zhangkun83 zhangkun83 modified the milestones: 1.2, 1.1 Jan 12, 2017
@carl-mastrangelo carl-mastrangelo modified the milestones: Next, 1.2 Mar 16, 2017
ejona86 added a commit to ejona86/grpc-java that referenced this issue Jul 7, 2017
ejona86 added a commit to ejona86/grpc-java that referenced this issue Jul 17, 2017
ejona86 added a commit to ejona86/grpc-java that referenced this issue Jul 17, 2017
@zhangkun83
Copy link
Contributor Author

@ejona86 @dapengzhang0, I wonder if the fix should be:

  1. Only release the executors when channel is terminated
  2. newCall() and call.start() throw if channel is shutdown. Calling them after shutdown() is application's fault. They should and can consciously avoid it. This might be considered an API-breaking change though.

@ejona86
Copy link
Member

ejona86 commented Aug 2, 2017

@zhangkun83, I'm not sold on (2), but even if I was favorable toward it, it does seem like an API breakage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants