Add some workariunds for crashes on exit without closing all clients.

GitOrigin-RevId: 5c74e9fe6951b6a8eb65d6c1e5ddf7bf8e0c8163
This commit is contained in:
levlam 2020-10-11 21:21:38 +03:00
parent 66d8ee5228
commit 9856b0e46e
2 changed files with 13 additions and 5 deletions

View File

@ -176,9 +176,11 @@ class ClientManager::Impl final {
} }
} }
while (!tds_.empty() && !ExitGuard::is_exited()) { while (!tds_.empty() && !ExitGuard::is_exited()) {
receive(10); receive(0.1);
}
if (!ExitGuard::is_exited()) { // prevent closing of schedulers from already killed by OS threads
concurrent_scheduler_->finish();
} }
concurrent_scheduler_->finish();
} }
private: private:
@ -380,7 +382,9 @@ class MultiImpl {
Scheduler::instance()->finish(); Scheduler::instance()->finish();
} }
scheduler_thread_.join(); scheduler_thread_.join();
concurrent_scheduler_->finish(); if (!ExitGuard::is_exited()) { // prevent closing of schedulers from already killed by OS threads
concurrent_scheduler_->finish();
}
} }
private: private:
@ -519,11 +523,14 @@ class ClientManager::Impl final {
Impl(Impl &&) = delete; Impl(Impl &&) = delete;
Impl &operator=(Impl &&) = delete; Impl &operator=(Impl &&) = delete;
~Impl() { ~Impl() {
if (ExitGuard::is_exited()) {
return;
}
for (auto &it : impls_) { for (auto &it : impls_) {
close_impl(it.first); close_impl(it.first);
} }
while (!impls_.empty() && !ExitGuard::is_exited()) { while (!impls_.empty() && !ExitGuard::is_exited()) {
receive(10); receive(0.1);
} }
} }
@ -571,7 +578,7 @@ class Client::Impl final {
~Impl() { ~Impl() {
multi_impl_->close(td_id_); multi_impl_->close(td_id_);
while (!ExitGuard::is_exited()) { while (!ExitGuard::is_exited()) {
auto response = receiver_.receive(10.0); auto response = receiver_.receive(0.1);
if (response.object == nullptr && response.client_id != 0 && response.request_id == 0) { if (response.object == nullptr && response.client_id != 0 && response.request_id == 0) {
break; break;
} }

View File

@ -111,6 +111,7 @@ void Scheduler::ServiceActor::tear_down() {
/*** SchedlerGuard ***/ /*** SchedlerGuard ***/
SchedulerGuard::SchedulerGuard(Scheduler *scheduler, bool lock) : scheduler_(scheduler) { SchedulerGuard::SchedulerGuard(Scheduler *scheduler, bool lock) : scheduler_(scheduler) {
if (lock) { if (lock) {
// the next check can fail if OS killed the scheduler's thread without releasing the guard
CHECK(!scheduler_->has_guard_); CHECK(!scheduler_->has_guard_);
scheduler_->has_guard_ = true; scheduler_->has_guard_ = true;
} }