Fix double increase of total_timeout in NetQueryDelayer and SequenceDispatcher.

This commit is contained in:
levlam 2022-08-02 16:51:56 +03:00
parent 90b04eb3b6
commit a817dc8dd0
2 changed files with 18 additions and 10 deletions

View File

@ -146,6 +146,7 @@ void SequenceDispatcher::on_result(NetQueryPtr query) {
data_[i].last_timeout_ = query->last_timeout_; data_[i].last_timeout_ = query->last_timeout_;
check_timeout(data_[i]); check_timeout(data_[i]);
} }
query->last_timeout_ = 0;
} }
if (query->is_error() && (query->error().code() == NetQuery::ResendInvokeAfter || if (query->is_error() && (query->error().code() == NetQuery::ResendInvokeAfter ||
@ -323,14 +324,18 @@ class MultiSequenceDispatcherImpl final : public MultiSequenceDispatcher {
if (net_query.empty() || net_query->is_ready()) { if (net_query.empty() || net_query->is_ready()) {
return false; return false;
} }
net_query->total_timeout_ += node.total_timeout; if (node.total_timeout > 0) {
node.total_timeout = 0; net_query->total_timeout_ += node.total_timeout;
if (net_query->total_timeout_ > net_query->total_timeout_limit_) { LOG(INFO) << "Set total_timeout to " << net_query->total_timeout_ << " for " << net_query->id();
LOG(WARNING) << "Fail " << net_query << " to " << net_query->source_ << " because total_timeout " node.total_timeout = 0;
<< net_query->total_timeout_ << " is greater than total_timeout_limit "
<< net_query->total_timeout_limit_; if (net_query->total_timeout_ > net_query->total_timeout_limit_) {
net_query->set_error(Status::Error(429, PSLICE() << "Too Many Requests: retry after " << node.last_timeout)); LOG(WARNING) << "Fail " << net_query << " to " << net_query->source_ << " because total_timeout "
return true; << net_query->total_timeout_ << " is greater than total_timeout_limit "
<< net_query->total_timeout_limit_;
net_query->set_error(Status::Error(429, PSLICE() << "Too Many Requests: retry after " << node.last_timeout));
return true;
}
} }
return false; return false;
} }
@ -345,15 +350,17 @@ class MultiSequenceDispatcherImpl final : public MultiSequenceDispatcher {
auto tl_constructor = query->tl_constructor(); auto tl_constructor = query->tl_constructor();
scheduler_.for_each_dependent(task_id, [&](TaskId child_task_id) { scheduler_.for_each_dependent(task_id, [&](TaskId child_task_id) {
auto &child_node = *scheduler_.get_task_extra(child_task_id); auto &child_node = *scheduler_.get_task_extra(child_task_id);
if (child_node.net_query_ref->tl_constructor() == tl_constructor) { if (child_node.net_query_ref->tl_constructor() == tl_constructor && child_task_id != task_id) {
child_node.total_timeout += query->last_timeout_; child_node.total_timeout += query->last_timeout_;
child_node.last_timeout = query->last_timeout_; child_node.last_timeout = query->last_timeout_;
to_check_timeout.push_back(child_task_id); to_check_timeout.push_back(child_task_id);
} }
}); });
query->last_timeout_ = 0;
for (auto dependent_task_id : to_check_timeout) { for (auto dependent_task_id : to_check_timeout) {
if (check_timeout(*scheduler_.get_task_extra(dependent_task_id))) { auto &child_node = *scheduler_.get_task_extra(dependent_task_id);
if (check_timeout(child_node)) {
scheduler_.pause_task(dependent_task_id); scheduler_.pause_task(dependent_task_id);
try_resend(dependent_task_id); try_resend(dependent_task_id);
} }

View File

@ -56,6 +56,7 @@ void NetQueryDelayer::delay(NetQueryPtr query) {
} }
query->total_timeout_ += timeout; query->total_timeout_ += timeout;
query->last_timeout_ = timeout; query->last_timeout_ = timeout;
LOG(INGO) << "Set total_timeout to " << query->total_timeout_ << " for " << query->id();
auto error = query->error().move_as_error(); auto error = query->error().move_as_error();
query->resend(); query->resend();