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

Grpc-Java : make sure to call shutdown()/shutdownNow() and wait until awaitTermination #5315

Closed
chsi13 opened this issue Feb 4, 2019 · 7 comments
Labels

Comments

@chsi13
Copy link

chsi13 commented Feb 4, 2019

Please answer these questions before submitting your issue.

What version of gRPC are you using?

grpc-core 1.13.1

image

What did you expect to see?

I saw lot ====> of .g.i.ManagedChannelOrphanWrapper : ~* Channel ManagedChannelImpl{logId=5, target=172.30.84.17:6565} was not shutdown properly!!! *~
Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.

java.lang.RuntimeException: ManagedChannel allocation site
at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.(ManagedChannelOrphanWrapper.java:103)
at io.grpc.internal.ManagedChannelOrphanWrapper.(ManagedChannelOrphanWrapper.java:53)

following each errors (StatusRuntimeException)

Client code :

ManagedChannel channel = ManagedChannelBuilder.forAddress(this.host, this.port).usePlaintext().intercept(interceptors).build();
    T t = runner.apply(stubSupplier.apply(channel).withDeadlineAfter(timeout, TimeUnit.MILLISECONDS));
    try {
      channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
      return t;
    } catch (InterruptedException e) {
      throw new IllegalStateException("Error happened during shutdown of validator gRPC channel", e);
    }

I start a new channel by request. Is-it correct ?

shutdown not done efficiently ?

@carl-mastrangelo
Copy link
Contributor

This changed in recent versions of gRPC to only require shutdown(). Your code doesn't handle InterruptedException properly, and the RPC should be inside of the try block (if it throws, the channel wouldn't shutdown).

@chsi13
Copy link
Author

chsi13 commented Feb 4, 2019

Which version ? So the rpc in the try and only Channel.shutdown(); in a finally block + interrupt flag to true if interruptedException ?? Is it right?

@carl-mastrangelo
Copy link
Contributor

The PR was #5283 which will end up in the 1.19 release (1.18 happens next week).

So the rpc in the try and only Channel.shutdown(); in a finally block + interrupt flag to true if interruptedException ?? Is it right?

Correct.

@chsi13
Copy link
Author

chsi13 commented Feb 4, 2019

So waiting for 1.19.. should I keep the code 'shutdown().awaitTermination(..)??

@chsi13
Copy link
Author

chsi13 commented Feb 5, 2019

Hi.

I switch to grpc-netty and grpc-services 1.18.0.

image

But continue to have errors : java.lang.RuntimeException: ManagedChannel allocation site

I change my client code to :

 ManagedChannel channel = ManagedChannelBuilder.forAddress(this.host, this.port).usePlaintext().intercept(interceptors).build();
    try {
      return runner.apply(stubSupplier.apply(channel).withDeadlineAfter(timeout, TimeUnit.MILLISECONDS));
    } finally {
      try {
        channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        LOGGER.warn("Interrupted exception during gRPC channel close", e);
        Thread.currentThread().interrupt();
      }
    }

@laymain
Copy link

laymain commented May 2, 2019

Same here with the InProcessServerBuilder and gRPC 1.20.0

String name = UUID.randomUUID().toString();
Server server = InProcessServerBuilder.forName(name).addService(service).build();
server.start();
try {
    // do whatever....
} finally {
    server.shutdownNow().awaitTermination();
}
Channel ManagedChannelImpl{logId=44, target=directaddress:///8158b613-fec5-4656-a664-16c689b56f3b} was not shutdown properly!!! ~*~*~*
    Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.
java.lang.RuntimeException: ManagedChannel allocation site
	at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init>(ManagedChannelOrphanWrapper.java:94)
	at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:52)
	at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:43)
	at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:527)

dmitrykuzmin added a commit to spine-examples/todo-list that referenced this issue Oct 3, 2019
It seems there is nothing we can do for now.

Looks somewhat similar to grpc/grpc-java#5315.

The test output is not hidden behind the `MuteLogging` so the
problem is still apparent during the build.
@ejona86 ejona86 removed this from the Unscheduled milestone Mar 26, 2020
@ejona86
Copy link
Member

ejona86 commented Mar 26, 2020

Closing, since this should have long-ago been fixed.

@laymain, it seems your comment wasn't seen before. You're code snippet is for a Server but the exception is for a Channel, so you still may have a bug elsewhere in your code.

If anyone experiences this with gRPC v1.19 or later, then please open a new issue.

@ejona86 ejona86 closed this as completed Mar 26, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants