Skip to content

Commit 6a2026b

Browse files
author
Alexander Furer
committed
fixed NPE during destroy if server has not stated
1 parent bf0024e commit 6a2026b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

grpc-spring-boot-starter/src/main/java/org/lognet/springboot/grpc/GRpcServerRunner.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,14 @@ private void startDaemonAwaitThread() {
149149

150150
@Override
151151
public void destroy() throws Exception {
152-
log.info("Shutting down gRPC server ...");
153-
server.getServices().forEach(def->healthStatusManager.clearStatus(def.getServiceDescriptor().getName()));
154-
Optional.ofNullable(server).ifPresent(Server::shutdown);
155-
log.info("gRPC server stopped.");
152+
153+
Optional.ofNullable(server).ifPresent(s->{
154+
log.info("Shutting down gRPC server ...");
155+
s.getServices().forEach(def->healthStatusManager.clearStatus(def.getServiceDescriptor().getName()));
156+
s.shutdown();
157+
log.info("gRPC server stopped.");
158+
});
159+
156160
}
157161

158162
private <T> Stream<String> getBeanNamesByTypeWithAnnotation(Class<? extends Annotation> annotationType, Class<T> beanType) throws Exception {

0 commit comments

Comments
 (0)