Skip to content

Commit

Permalink
[Improvement] Shutdown the grpc executors pool when closing (#83)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
[Improvement] Shutdown the grpc executors pool when closing

### Why are the changes needed?
Although the executor pool is used in grpc, but the grpc server won't take ownership of the given executor. It's caller's responsibility to shut down the executor when it's desired.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
No need.
  • Loading branch information
zuston committed Jul 26, 2022
1 parent 0a866f6 commit 3522e07
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ public class GrpcServer implements ServerInterface {

private final Server server;
private final int port;
private final ExecutorService pool;

public GrpcServer(RssBaseConf conf, BindableService service, GRPCMetrics grpcMetrics) {
this.port = conf.getInteger(RssBaseConf.RPC_SERVER_PORT);
long maxInboundMessageSize = conf.getLong(RssBaseConf.RPC_MESSAGE_MAX_SIZE);
int rpcExecutorSize = conf.getInteger(RssBaseConf.RPC_EXECUTOR_SIZE);
ExecutorService pool = new ThreadPoolExecutor(
pool = new ThreadPoolExecutor(
rpcExecutorSize,
rpcExecutorSize * 2,
10,
Expand Down Expand Up @@ -89,6 +90,9 @@ public void stop() throws InterruptedException {
server.shutdown().awaitTermination(10, TimeUnit.SECONDS);
LOG.info("GRPC server stopped!");
}
if (pool != null) {
pool.shutdown();
}
}

public void blockUntilShutdown() throws InterruptedException {
Expand Down

0 comments on commit 3522e07

Please sign in to comment.