Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reasonable backoff strategies #21

Open
mempirate opened this issue Oct 20, 2023 · 0 comments
Open

Reasonable backoff strategies #21

mempirate opened this issue Oct 20, 2023 · 0 comments
Assignees
Labels
A-transport Area: Transports C-fix Category: Fix
Milestone

Comments

@mempirate
Copy link
Contributor

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();
}

@mempirate mempirate added C-fix Category: Fix A-transport Area: Transports labels Oct 20, 2023
@mempirate mempirate added this to the v0.1.1-alpha milestone Oct 20, 2023
@mempirate mempirate self-assigned this Oct 20, 2023
@mempirate mempirate modified the milestones: v0.1.1-alpha, v0.1.2-alpha Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transport Area: Transports C-fix Category: Fix
Projects
None yet
Development

No branches or pull requests

1 participant