-
Notifications
You must be signed in to change notification settings - Fork 265
fix(iroh): always ping new paths, add test for reconnecting with changed addrs #3372
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
14c6d1d
9866f0e
087f003
a00644a
a8ee257
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3216,4 +3216,85 @@ mod tests { | |
|
||
Ok(()) | ||
} | ||
|
||
/// Test that we can immediately reconnect after respawning an endpoint with the same node id. | ||
#[tokio::test] | ||
#[traced_test] | ||
async fn can_abort_and_reconnect() -> Result { | ||
const TEST_ALPN: &[u8] = b"/iroh/test/1"; | ||
const TIMEOUT: Duration = Duration::from_secs(5); | ||
|
||
let mut rng = &mut rand_chacha::ChaCha12Rng::seed_from_u64(1); | ||
|
||
// Spawn a server endpoint. | ||
let server = Endpoint::builder() | ||
.secret_key(SecretKey::generate(&mut rng)) | ||
.relay_mode(RelayMode::Disabled) | ||
.alpns(vec![TEST_ALPN.to_vec()]) | ||
.bind() | ||
.await?; | ||
let server_addr = server.node_addr().initialized().await.e()?; | ||
|
||
// The server accepts all connections, waits for them being closed, and sends the | ||
// close code over a channel. | ||
let (tx, mut rx) = tokio::sync::mpsc::channel(1); | ||
let server_loop = tokio::task::spawn(async move { | ||
while let Some(conn) = server.accept().await { | ||
let conn = conn.accept().e()?.await.e()?; | ||
let res = match conn.closed().await { | ||
ConnectionError::ApplicationClosed(frame) => Ok(u64::from(frame.error_code)), | ||
reason => Err(reason), | ||
}; | ||
tx.send(res).await.e()?; | ||
} | ||
Result::<_, n0_snafu::Error>::Ok(()) | ||
}); | ||
|
||
// Clients connect to the server, and immediately close the connection with a code | ||
// and then close the endpoint. | ||
async fn connect(secret_key: SecretKey, addr: NodeAddr, code: u32) -> Result<Endpoint> { | ||
info!("spawn client node {}", secret_key.public().fmt_short()); | ||
let ep = Endpoint::builder() | ||
.secret_key(secret_key) | ||
.relay_mode(RelayMode::Disabled) | ||
.bind() | ||
.await?; | ||
info!( | ||
"connect client {} ({:?}) to {addr:?}", | ||
ep.node_id().fmt_short(), | ||
ep.bound_sockets(), | ||
); | ||
let conn = ep.connect(addr, TEST_ALPN).await?; | ||
conn.close(code.into(), b"bye"); | ||
Ok(ep) | ||
} | ||
|
||
let client_secret_key = SecretKey::generate(&mut rng); | ||
|
||
// First connection | ||
let ep = n0_future::time::timeout( | ||
TIMEOUT, | ||
connect(client_secret_key.clone(), server_addr.clone(), 23), | ||
) | ||
.await | ||
.e()??; | ||
assert_eq!(rx.recv().await.unwrap().unwrap(), 23); | ||
// close the endpoint in a separate task, to not lose time for our immediate respawn testing | ||
let close1 = tokio::task::spawn(async move { ep.close().await }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How long does this take? Since both endpoints are still there this should be pretty fast, no? Feels a bit odd to spawn this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I'll remove it again. It was a trial for the windows failure, but that's not it, see comment below |
||
|
||
// Second connection | ||
let ep = n0_future::time::timeout( | ||
TIMEOUT, | ||
connect(client_secret_key.clone(), server_addr.clone(), 24), | ||
) | ||
.await | ||
.e()??; | ||
assert_eq!(rx.recv().await.unwrap().unwrap(), 24); | ||
|
||
close1.await.e()?; | ||
ep.close().await; | ||
server_loop.abort(); | ||
|
||
Ok(()) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.