before this change, `stop_signal::wait()` waits until it receives
`SIGTERM` or `SIGINT`, but we also need to stop the service per the
request of monitor or when a serious health condition is detected.
so, an `abort_source` should allow the server to request abort by
itself. also, as the single truth of stop, `stop_signal` will be
able to send the message to its subscribers to abort any "blocking"
calls which might prevent or delay the stop process.
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
#pragma once
-#include <seastar/core/sharded.hh>
+#include <seastar/core/abort_source.hh>
#include <seastar/core/reactor.hh>
#include <seastar/core/condition-variable.hh>
/// });
/// \endcode
class stop_signal {
- bool _caught = false;
seastar::condition_variable _cond;
+ seastar::abort_source _abort_source;
+
private:
void signaled() {
- if (_caught) {
+ if (stopping()) {
return;
}
- _caught = true;
+ _abort_source.request_abort();
_cond.broadcast();
}
public:
seastar::engine().handle_signal(SIGTERM, [] {});
}
seastar::future<> wait() {
- return _cond.wait([this] { return _caught; });
+ return _cond.wait([this] { return _abort_source.abort_requested(); });
}
bool stopping() const {
- return _caught;
+ return _abort_source.abort_requested();
+ }
+ auto& abort_source() {
+ return _abort_source;
}
};
}