mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-05-02 01:53:08 +03:00
[cdc_stream] Implement stop-service command (#29)
Implements cdc_stream stop-service. Also fixes an issue in the BackgroundService implementation where Exit() would deadlock since server shutdown waits for all RPCs to exit.
This commit is contained in:
@@ -23,7 +23,12 @@ namespace cdc_ft {
|
||||
|
||||
BackgroundServiceImpl::BackgroundServiceImpl() {}
|
||||
|
||||
BackgroundServiceImpl::~BackgroundServiceImpl() = default;
|
||||
BackgroundServiceImpl::~BackgroundServiceImpl() {
|
||||
if (exit_thread_) {
|
||||
exit_thread_->join();
|
||||
exit_thread_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundServiceImpl::SetExitCallback(ExitCallback exit_callback) {
|
||||
exit_callback_ = std::move(exit_callback);
|
||||
@@ -33,8 +38,11 @@ grpc::Status BackgroundServiceImpl::Exit(grpc::ServerContext* context,
|
||||
const EmptyProto* request,
|
||||
EmptyProto* response) {
|
||||
LOG_INFO("RPC:Exit");
|
||||
if (exit_callback_) {
|
||||
return ToGrpcStatus(exit_callback_());
|
||||
if (exit_callback_ && !exit_thread_) {
|
||||
// Fire up a thread so call the callback, since shutting down a server
|
||||
// won't finish until all RPCs are done.
|
||||
exit_thread_ =
|
||||
std::make_unique<std::thread>([cb = &exit_callback_]() { (*cb)(); });
|
||||
}
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user