Skip to content

Reasonable backoff strategies #21

Open
@mempirate

Description

@mempirate

Context

Our current backoff strategy is just retrying every 100ms. This should be configurable, and we should support both linear and exponential backoff strategies.

The current code is here:

fn on_disconnect(mut self: Pin<&mut Self>, cx: &mut Context<'_>) {
// We copy here because we can't do it after borrowing self in the match below
let endpoint = self.endpoint;
match &mut self.state {
SessionState::Connected(_) => {
error!("Session was disconnected from {}", self.endpoint);
self.state = SessionState::Disconnected(ReconnectStatus {
attempts: 0,
current_attempt: Some(Io::establish(self.endpoint)),
});
}
SessionState::Disconnected(reconnect_status) => {
debug!(
attempts = reconnect_status.attempts,
"Reconnect failed, retrying..."
);
reconnect_status.attempts += 1;
// Start and set the new reconnect attempt
let attempt = Box::pin(async move {
tokio::time::sleep(Duration::from_millis(100)).await;
Io::establish(endpoint).await
});
reconnect_status.current_attempt = Some(attempt);
}
SessionState::Processing(_) => {
error!("Session was disconnected from {}", self.endpoint);
self.state = SessionState::Disconnected(ReconnectStatus {
attempts: 0,
current_attempt: Some(Io::establish(self.endpoint)),
});
}
SessionState::Terminated(_) => {
unreachable!("Session was already terminated")
}
}
// Register the waker to make sure the reconnect attempt is polled
cx.waker().wake_by_ref();
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions