Make shutdown faster in case of a long running event handler#2
Make shutdown faster in case of a long running event handler#2
Conversation
The event loop did not close until every filesystem change was processed, and every change restarted the listening. With this commit when we're shutting down, we do not listen for new changes anymore.
|
Thanks for that Pull Request. I tried it out but found another Problem (Sorry for that 😊). It seems like the |
|
I did some further analysis to this and i think the root of the lies in the |
|
One Solution which works for me was to change the I just have added the following: void FsWatcher::processEvent(DWORD numberOfBytesTrs, OVERLAPPED* overlapped) {
...
if (this->shuttingDown) {
watchInfoIt->second.state = WatchInfo::State::PendingClose;
}
if (watchInfoIt->second.state == WatchInfo::State::Listening) {
....
}
if (numberOfBytes == 0 || this->shuttingDown) {
if (watchInfoIt->second.state == WatchInfo::State::PendingClose) {
std::cout << "Erease WatchInfo " << watchInfoIt->second.rId << "\n";
this->watchInfos.erase(watchInfoIt);
} else {
std::cout << "Error: " << GetLastError() << '\n';
this->errorEvent(watchInfoIt->second.rId);
}
return;
}
....
} |
As detailed in issue #1 if
changeEvent()takes a long time and new filesystem events keep happening, then the shutdown of the application is delayed.This PR solves that problem by not processing entirely these events during shutdown.