Skip to content

Commit

Permalink
Fix drainer can't be stopped or crashed while stopping (vesoft-inc#2894)
Browse files Browse the repository at this point in the history
* fix stop crashed

* fix can't exit
  • Loading branch information
critical27 committed Jul 4, 2023
1 parent 38a829c commit 33e413f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/drainer/DrainerServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ bool DrainerServer::start() {
}

void DrainerServer::waitUntilStop() {
std::unique_lock<std::mutex> lkStop(muStop_);
while (drainerSvcStatus_ == STATUS_RUNNING) {
cvStop_.wait(lkStop);
{
std::unique_lock<std::mutex> lkStop(muStop_);
while (drainerSvcStatus_ == STATUS_RUNNING) {
cvStop_.wait(lkStop);
}
}

this->stop();
Expand Down Expand Up @@ -157,14 +159,16 @@ void DrainerServer::stop() {
metaClient_->stop();
}

// File operations are not allowed when exiting
std::lock_guard<std::mutex> lrk(env_->recvLogMutex_);
std::lock_guard<std::mutex> slk(env_->sendLogMutex_);
for (auto& fd : env_->recvLogIdFd_) {
close(fd.second);
}
for (auto& fd : env_->sendLogIdFd_) {
close(fd.second);
if (env_) {
// File operations are not allowed when exiting
std::lock_guard<std::mutex> lrk(env_->recvLogMutex_);
std::lock_guard<std::mutex> slk(env_->sendLogMutex_);
for (auto& fd : env_->recvLogIdFd_) {
close(fd.second);
}
for (auto& fd : env_->sendLogIdFd_) {
close(fd.second);
}
}
}

Expand Down

0 comments on commit 33e413f

Please sign in to comment.