Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 208dcdb

Browse files
committed
fix: Gracefully shutdown grpc channel on shutdown
1 parent 696634c commit 208dcdb

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/main/java/io/contract_testing/contractcase/client/AbstractRpcConnector.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.contract_testing.contractcase.grpc.ContractCaseGrpc.ContractCaseStub;
1414
import io.contract_testing.contractcase.grpc.ContractCaseStream.BoundaryResult;
1515
import io.contract_testing.contractcase.grpc.ContractCaseStream.ResultResponse;
16+
import io.grpc.ManagedChannel;
1617
import io.grpc.ManagedChannelBuilder;
1718
import io.grpc.Status;
1819
import io.grpc.stub.StreamObserver;
@@ -35,20 +36,22 @@ abstract class AbstractRpcConnector<T extends AbstractMessage, B extends Builder
3536
private final SendingWorker<T> worker;
3637
private Status errorStatus;
3738

39+
private ManagedChannel channel;
40+
3841
private static final int DEFAULT_TIMEOUT_SECONDS = 60;
3942

4043

4144
public AbstractRpcConnector(
4245
@NotNull LogPrinter logPrinter,
4346
@NotNull ConfigHandle configHandle,
4447
@NotNull RunTestCallback runTestCallback) {
48+
this.channel = ManagedChannelBuilder
49+
// TODO: Allow configuration of the port
50+
.forAddress("localhost", DEFAULT_PORT)
51+
.usePlaintext()
52+
.build();
4553
this.worker = new SendingWorker<T>(createConnection(
46-
ContractCaseGrpc.newStub(
47-
ManagedChannelBuilder
48-
// TODO: Allow configuration of the port
49-
.forAddress("localhost", DEFAULT_PORT)
50-
.usePlaintext()
51-
.build()),
54+
ContractCaseGrpc.newStub(channel),
5255
new ContractResponseStreamObserver<>(
5356
this,
5457
logPrinter,
@@ -182,6 +185,7 @@ public void setErrorStatus(Status errorStatus) {
182185

183186
public void close() {
184187
worker.close();
188+
this.channel.shutdown();
185189
}
186190

187191

0 commit comments

Comments
 (0)