Put incrementing error count to the Err branch of PollingStream::poll_next

This commit is contained in:
Сырцев Вадим Игоревич 2024-07-28 21:57:41 +03:00
parent 4f1a458fb7
commit dc125e3b65
No known key found for this signature in database
GPG key ID: D581B7E10673309B

View file

@ -450,7 +450,12 @@ impl<B: Requester> Stream for PollingStream<'_, B> {
*this.error_count = 0; *this.error_count = 0;
seconds.duration() seconds.duration()
} }
None => (this.polling.backoff_strategy)(*this.error_count), None => {
let delay = (this.polling.backoff_strategy)(*this.error_count);
*this.error_count = this.error_count.saturating_add(1);
log::trace!("current error count: {}", *this.error_count);
delay
}
}; };
log::info!("retrying getting updates in {}s", delay.as_secs()); log::info!("retrying getting updates in {}s", delay.as_secs());
this.eepy.set(Some(sleep(delay))); this.eepy.set(Some(sleep(delay)));
@ -462,9 +467,6 @@ impl<B: Requester> Stream for PollingStream<'_, B> {
// Poll eepy future until completion, needed for backoff strategy // Poll eepy future until completion, needed for backoff strategy
else if let Some(eepy) = this.eepy.as_mut().as_pin_mut() { else if let Some(eepy) = this.eepy.as_mut().as_pin_mut() {
ready!(eepy.poll(cx)); ready!(eepy.poll(cx));
// As soon as delay is waited we increment the counter
*this.error_count = this.error_count.saturating_add(1);
log::trace!("current error count: {}", *this.error_count);
log::trace!("backoff delay completed"); log::trace!("backoff delay completed");
this.eepy.as_mut().set(None); this.eepy.as_mut().set(None);
} }