Skip to content

Commit

Permalink
Merge pull request #65 from chainbound/fix/quic-reconnects
Browse files Browse the repository at this point in the history
fix(socket): fix subscriber reconnects with QUIC
  • Loading branch information
mempirate authored Jan 22, 2024
2 parents 1ebdc7d + 2a26e5b commit 6ce84a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion msg-socket/src/pub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ mod tests {
// Try to connect and subscribe before the publisher is up
sub_socket.connect("0.0.0.0:6662").await.unwrap();
sub_socket.subscribe("HELLO".to_string()).await.unwrap();
tokio::time::sleep(Duration::from_millis(500)).await;
tokio::time::sleep(Duration::from_millis(1000)).await;

pub_socket.bind("0.0.0.0:6662").await.unwrap();
tokio::time::sleep(Duration::from_millis(2000)).await;
Expand Down
18 changes: 17 additions & 1 deletion msg-socket/src/sub/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,25 @@ where
/// De-activates a publisher by setting it to [`PublisherState::Inactive`]. This will initialize
/// the backoff stream.
fn reset_publisher(&mut self, addr: SocketAddr) {
tracing::debug!("Resetting publisher at {addr:?}");
self.publishers.insert(
addr,
PublisherState::Inactive {
addr,
backoff: ExponentialBackoff::new(Duration::from_millis(10), 16),
backoff: ExponentialBackoff::new(Duration::from_millis(50), 16),
},
);
}

/// Returns true if we're already connected to the given publisher address.
fn is_connected(&self, addr: &SocketAddr) -> bool {
if let Some(PublisherState::Active { .. }) = self.publishers.get(addr) {
return true;
}

false
}

/// Subscribes to a topic on all publishers.
fn subscribe(&mut self, topic: String) {
let mut inactive = Vec::new();
Expand Down Expand Up @@ -273,6 +283,12 @@ where
}

fn on_connection(&mut self, addr: SocketAddr, io: T::Io) {
if self.is_connected(&addr) {
// We're already connected to this publisher
warn!(%addr, "Already connected to publisher");
return;
}

// This should spawn a new task tied to this connection, and
debug!("Connection to {} established, spawning session", addr);

Expand Down

0 comments on commit 6ce84a9

Please sign in to comment.