Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Oct 12, 2019

We were feeding gRPC an executor, but neglecting to shut it down, which caused the JVM to hang at shutdown when running inside IntelliJ. The gRPC documentation requires that we shut down executors ourselves: https://grpc.github.io/grpc-java/javadoc/io/grpc/ServerBuilder.html#executor-java.util.concurrent.Executor-

Not too sure how to write a unit test for this - it clearly doesn't occur inside the Maven/JUnit unit test runner.

Travis: https://travis-ci.com/lihalite/arrow/builds/131648977

@github-actions
Copy link

Copy link
Contributor

Choose a reason for hiding this comment

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

If server.shutdown() fails, we will leak resources (fail to invoke AutoCloseables.close)?

Copy link
Author

Choose a reason for hiding this comment

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

We could, but server.shutdown doesn't throw any checked exceptions. I can move it into a finally block though.

Copy link
Author

Choose a reason for hiding this comment

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

Er, no, I can't, since I don't want to shut down the executor before the server itself shuts down.

Copy link
Contributor

Choose a reason for hiding this comment

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

why shutdownNow and not shutdown?

Copy link
Author

Choose a reason for hiding this comment

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

I was worried about it blocking but on reflection, if we make it to closing the executor, the gRPC server should be shut down and everything should be terminated. I've changed it and updated the comment to explain.

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems like it would be clearer to remove the ternary operator combine the resources cleanup into one if/then block?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, consolidated them.

@emkornfield
Copy link
Contributor

Not too sure how to write a unit test for this - it clearly doesn't occur inside the Maven/JUnit unit test runner.

At the very least you should be able to test for the post condition that the executor passed in is terminated after a call to close.

@ghost
Copy link
Author

ghost commented Oct 23, 2019

Not too sure how to write a unit test for this - it clearly doesn't occur inside the Maven/JUnit unit test runner.

At the very least you should be able to test for the post condition that the executor passed in is terminated after a call to close.

Yes, I've added two tests to cover the two cases.

Apologies for the delay, I got tied up at work.

Copy link
Contributor

Choose a reason for hiding this comment

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

can't you try shutting down here and verify it does shutdown?

Copy link
Author

Choose a reason for hiding this comment

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

No, there's no accessible reference to the actual executor to confirm it afterwards.

Copy link
Author

Choose a reason for hiding this comment

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

I could plumb one through, but it'd be adding references specifically for testing.

(Sorry for the delay again, October was quite the busy month.)

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about making resources less generic and take the reference to ExecutorService in the class instead of list of AutoCloseable? Then make awaitTermination rely on both the server and the executor (if its not null). That way you don't need anything specifically visible for testing.

Copy link
Author

Choose a reason for hiding this comment

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

That makes sense. I've updated the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could avoid exposing this if you added this to awaitTermination as well (but that is a little tricky to do correctly). I'm OK if you don't want to do it.

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, how would that work in the test? We'd shut down the executor in awaitTermination and wait?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would have thought we shutdown the executorservice in shutdown

Copy link
Member

Choose a reason for hiding this comment

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

Er, right. I can do that, but I still don't see how that'd let us avoid exposing it in test.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think it tests the behavior implicitly vs explicitly as the way you have it now. Like I said I'm fine with either approach.

@emkornfield
Copy link
Contributor

+1 merging.

@lidavidm
Copy link
Member

Thank you! Apologies this dragged out so long.

pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
We were feeding gRPC an executor, but neglecting to shut it down, which caused the JVM to hang at shutdown when running inside IntelliJ. The gRPC documentation requires that we shut down executors ourselves: https://grpc.github.io/grpc-java/javadoc/io/grpc/ServerBuilder.html#executor-java.util.concurrent.Executor-

Not too sure how to write a unit test for this - it clearly doesn't occur inside the Maven/JUnit unit test runner.

Travis: https://travis-ci.com/lihalite/arrow/builds/131648977

Closes apache#5634 from lihalite/arrow-6867 and squashes the following commits:

60a4201 <David Li> ARROW-6867:  clean up default executor

Authored-by: David Li <li.davidm96@gmail.com>
Signed-off-by: Micah Kornfield <emkornfield@gmail.com>
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.

3 participants