简体   繁体   中英

node js grpc server forceShutdown doesn't shut down properly

I'm trying to restart a grpc node js server after shutting it down

The first time the grpc server starts it is ok, but trying to start after forceShutdown gives the error:

Error: Server is already running

This is the code:

server.start(); // runs ok 
server.forceShutdown();
server.start(); // gives error

How to shut down grpc server properly so that it can be restarted like above?

It seems like a bug on gRPC's part. According to their docs:

When it returns, the server has shut down.

Meaning that when the function call returns, the server should be shut down, but it doesn't seem like that's the case as illustrated by your issue. You could try calling for a graceful shutdown and passing a callback that should be executed when the server has been shut down, and then immediately afterwards call for a forceful shutdown:

server.start();
server.tryShutdown(function () {
  server.start();
});
server.forceShutdown();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM