ibzib commented on a change in pull request #11537: URL: https://github.com/apache/beam/pull/11537#discussion_r416024189
########## File path: runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/environment/ExternalEnvironmentFactory.java ########## @@ -145,17 +149,23 @@ public InstructionRequestHandler getInstructionRequestHandler() { @Override public void close() throws Exception { - finalInstructionHandler.close(); - BeamFnApi.StopWorkerRequest stopWorkerRequest = - BeamFnApi.StopWorkerRequest.newBuilder().setWorkerId(workerId).build(); - LOG.debug("Closing worker ID {}", workerId); - BeamFnApi.StopWorkerResponse stopWorkerResponse = - BeamFnExternalWorkerPoolGrpc.newBlockingStub( - ManagedChannelFactory.createDefault() - .forDescriptor(externalPayload.getEndpoint())) - .stopWorker(stopWorkerRequest); - if (!stopWorkerResponse.getError().isEmpty()) { - throw new RuntimeException(stopWorkerResponse.getError()); + try { + finalInstructionHandler.close(); + BeamFnApi.StopWorkerRequest stopWorkerRequest = + BeamFnApi.StopWorkerRequest.newBuilder().setWorkerId(workerId).build(); + LOG.debug("Closing worker ID {}", workerId); + BeamFnApi.StopWorkerResponse stopWorkerResponse = + BeamFnExternalWorkerPoolGrpc.newBlockingStub(managedChannel) + .stopWorker(stopWorkerRequest); + if (!stopWorkerResponse.getError().isEmpty()) { + throw new RuntimeException(stopWorkerResponse.getError()); + } + } finally { + managedChannel.shutdown(); + managedChannel.awaitTermination(10, TimeUnit.SECONDS); Review comment: Nit: awaitTermination already returns whether the channel is terminated, so no need to call isTerminated ########## File path: runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/environment/ExternalEnvironmentFactory.java ########## @@ -145,17 +149,23 @@ public InstructionRequestHandler getInstructionRequestHandler() { @Override public void close() throws Exception { - finalInstructionHandler.close(); - BeamFnApi.StopWorkerRequest stopWorkerRequest = - BeamFnApi.StopWorkerRequest.newBuilder().setWorkerId(workerId).build(); - LOG.debug("Closing worker ID {}", workerId); - BeamFnApi.StopWorkerResponse stopWorkerResponse = - BeamFnExternalWorkerPoolGrpc.newBlockingStub( - ManagedChannelFactory.createDefault() - .forDescriptor(externalPayload.getEndpoint())) - .stopWorker(stopWorkerRequest); - if (!stopWorkerResponse.getError().isEmpty()) { - throw new RuntimeException(stopWorkerResponse.getError()); + try { + finalInstructionHandler.close(); + BeamFnApi.StopWorkerRequest stopWorkerRequest = + BeamFnApi.StopWorkerRequest.newBuilder().setWorkerId(workerId).build(); + LOG.debug("Closing worker ID {}", workerId); + BeamFnApi.StopWorkerResponse stopWorkerResponse = + BeamFnExternalWorkerPoolGrpc.newBlockingStub(managedChannel) + .stopWorker(stopWorkerRequest); + if (!stopWorkerResponse.getError().isEmpty()) { + throw new RuntimeException(stopWorkerResponse.getError()); + } + } finally { + managedChannel.shutdown(); + managedChannel.awaitTermination(10, TimeUnit.SECONDS); Review comment: Why 10 seconds? Does shutdown usually take that long? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org