File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,28 @@ runs a main loop in `HandleRpcs` to query the queue:
195195 }
196196```
197197
198+ ### Shutting Down the Server
199+ We've been using a completion queue to get the async notifications. Care must be
200+ taken to shut it down *after* the server has also been shut down.
201+
202+ Remember we got our completion queue instance `cq_` in `ServerImpl::Run()` by
203+ running `cq_ = builder.AddCompletionQueue()`. Looking at
204+ `ServerBuilder::AddCompletionQueue`'s documentation we see that
205+
206+ > ... Caller is required to shutdown the server prior to shutting down the
207+ > returned completion queue.
208+
209+ Refer to `ServerBuilder::AddCompletionQueue`'s full docstring for more details.
210+ What this means in our example is that `ServerImpl's` destructor looks like:
211+
212+ ```
213+ ~ ServerImpl() {
214+ server_ ->Shutdown();
215+ // Always shutdown the completion queue after the server.
216+ cq_ ->Shutdown();
217+ }
218+ ```
219+
198220You can see our complete server example in
199221[greeter_async_server.cc](https://github.com/grpc/grpc/blob/{{
200222site.data.config.grpc_release_branch
You can’t perform that action at this time.
0 commit comments