thrift/server: Retry with backoff for some error types

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
This commit is contained in:
Duarte Nunes
2017-11-09 15:31:55 +00:00
parent f367dbe1ed
commit b5cf1a152f

View File

@@ -50,6 +50,8 @@ using namespace apache::thrift::protocol;
using namespace apache::thrift::async;
using namespace ::cassandra;
using namespace std::chrono_literals;
class thrift_stats {
seastar::metrics::metric_groups _metrics;
public:
@@ -206,7 +208,14 @@ thrift_server::do_accepts(int which, bool keepalive) {
do_accepts(which, keepalive);
}).handle_exception([this, which, keepalive] (auto ex) {
tlogger.debug("accept failed {}", ex);
auto retry = [this, which, keepalive] { do_accepts(which, keepalive); };
auto retry = [this, which, keepalive] {
tlogger.debug("retrying accept after failure");
do_accepts(which, keepalive);
};
auto retry_with_backoff = [&] {
// FIXME: Consider using exponential backoff
sleep(1ms).then([retry = std::move(retry)] { retry(); });
};
try {
std::rethrow_exception(std::move(ex));
} catch (const std::system_error& e) {
@@ -214,9 +223,15 @@ thrift_server::do_accepts(int which, bool keepalive) {
// FIXME: Don't retry for other fatal errors
case EBADF:
break;
case ENFILE:
case EMFILE:
case ENOMEM:
retry_with_backoff();
default:
retry();
}
} catch (const std::bad_alloc&) {
retry_with_backoff();
} catch (...) {
retry();
}