diff --git a/include/grpc++/server.h b/include/grpc++/server.h index 6a15dcb37125da808f5853960bae83e364ec576a..a2bc097c7f759e3260da7d980314c5fb0629bf48 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -69,6 +69,7 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook { ShutdownInternal(TimePoint<T>(deadline).raw_time()); } + // Shutdown the server, waiting for all rpc processing to finish. void Shutdown() { ShutdownInternal(gpr_inf_future(GPR_CLOCK_MONOTONIC)); } // Block waiting for all work to complete (the server must either diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index b27aa3227603b8f3e5b10af3bc8d716bcfc1943d..8b213375295075b76d35b8525f059a44d2b00d92 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -329,11 +329,15 @@ void Server::ShutdownInternal(gpr_timespec deadline) { shutdown_ = true; grpc_server_shutdown_and_notify(server_, cq_.cq(), new ShutdownRequest()); cq_.Shutdown(); + // Spin, eating requests until the completion queue is completely shutdown. + // If the deadline expires then cancel anything that's pending and keep + // spinning forever until the work is actually drained. SyncRequest* request; bool ok; while (SyncRequest::AsyncWait(&cq_, &request, &ok, deadline)) { if (request == NULL) { // deadline expired grpc_server_cancel_all_calls(server_); + deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); } else if (ok) { SyncRequest::CallData call_data(this, request); }