Skip to content

Commit 1ccb3bb

Browse files
fix: make shutdown more graceful (#97)
* fix: make shutdown more graceful * chore: move health shutdown first * chore: also for http
1 parent fc0f3c2 commit 1ccb3bb

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

platform-grpc-service-framework/src/main/java/org/hypertrace/core/serviceframework/grpc/GrpcPlatformServiceContainer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hypertrace.core.serviceframework.grpc;
22

33
import static io.grpc.Deadline.after;
4+
import static java.util.Objects.nonNull;
45
import static java.util.concurrent.TimeUnit.MILLISECONDS;
56
import static java.util.concurrent.TimeUnit.SECONDS;
67

@@ -46,7 +47,7 @@
4647
@Slf4j
4748
abstract class GrpcPlatformServiceContainer extends PlatformService {
4849

49-
private List<ConstructedServer> servers;
50+
private List<ConstructedServer> servers = Collections.emptyList();
5051
private final List<PlatformPeriodicTaskDefinition> taskDefinitions = new LinkedList<>();
5152
private final List<ScheduledFuture<?>> scheduledFutures = new LinkedList<>();
5253
private ScheduledExecutorService periodicTaskExecutor;
@@ -187,13 +188,15 @@ private void awaitServerTermination(ConstructedServer constructedServer) {
187188

188189
@Override
189190
protected void doStop() {
190-
this.scheduledFutures.forEach(future -> future.cancel(true));
191191
healthStatusManager.enterTerminalState();
192-
grpcChannelRegistry.shutdown(after(10, SECONDS));
192+
this.scheduledFutures.forEach(future -> future.cancel(true));
193193
this.servers.forEach(
194194
constructedServer ->
195195
ServerManagementUtil.shutdownServer(
196196
constructedServer.getServer(), constructedServer.getName(), after(30, SECONDS)));
197+
if (nonNull(grpcChannelRegistry)) {
198+
grpcChannelRegistry.shutdown(after(10, SECONDS));
199+
}
197200
}
198201

199202
@Override

platform-http-service-framework/src/main/java/org/hypertrace/core/serviceframework/http/StandAloneHttpPlatformServiceContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ protected void doStart() {
4848
@Override
4949
protected void doStop() {
5050
log.info("Stopping service {}", this.getServiceName());
51-
grpcChannelRegistry.shutdown(after(10, SECONDS));
5251
this.container.stop();
52+
grpcChannelRegistry.shutdown(after(10, SECONDS));
5353
}
5454

5555
@Override

0 commit comments

Comments
 (0)