Fixes ANT-2026-VLPHAYRL. When an `ActiveRelayActor` stopped, it awaited `client_sink.close()` without a timeout and without reading its inboxes. tokio-websockets only finishes that close once the server ends the stream, so a relay that ignored the WebSocket Close kept the actor alive but deaf. The endpoint's `RelayActor` then blocked on it, through a route query or a full send queue, and the endpoint sent nothing through any relay. - `run_closing` replaces the untimed close. It gives up after `CLOSE_TIMEOUT` (1 s, below the `RelayActor`'s 3 s bound for shutting down its actors), and answers `HasEndpointRoute` with `false` meanwhile, like `sleep_backoff`. - The regression test, now `active_relay_answers_routes_and_exits_when_server_ignores_close`, runs without `#[ignore]`. It requires a route reply while the close hangs and then the actor's exit, and fails without either part of the fix. None. - This is a private security PR, so there is no public `ready-for-pr` issue. - Shutdown still closes gracefully: `run_closing` does not stop on the stop token, so honest relays still get a Close frame, just never waited on for more than 1 s. - [iroh#4686](https://github.com/n0-computer/iroh/pull/4686) (draft) fixes this as well, with a 3 s close timeout. It also bounds the `RelayActor`'s waits on its actors and retires stuck actors. That `RelayActor` side overlaps ANT-2026-2W9CJR5V ([iroh#4603](https://github.com/n0-computer/iroh/issues/4603)) and is left for that fix. - Bounding the close matches others: [coder/websocket](https://github.com/coder/websocket/blob/ac2177d22d91/close.go#L190-L204) allows 5 s to write the close frame and 5 s for the reply, [Node's `ws`](https://github.com/websockets/ws/blob/0cc9185755fa/lib/websocket.js#L1385-L1390) destroys the socket 30 s after it starts closing, and [RFC 6455 §7.1.1](https://www.rfc-editor.org/rfc/rfc6455#section-7.1.1) lets a client close the TCP connection when the server does not within a reasonable time. tokio-websockets waits for the peer without a limit, and [Gelbpunkt/tokio-websockets#128](https://github.com/Gelbpunkt/tokio-websockets/issues/128) (open) reports `Sink::poll_close` hanging. <details> <summary>Finding ANT-2026-VLPHAYRL (high, CWE-1088)</summary> > Relay ignoring WebSocket Close stalls ActiveRelayActor and all relay sends > > A relay server that an iroh endpoint connects to as a non-home relay > can permanently stop that endpoint from sending through any relay, > its home relay included, until the application closes the endpoint > and builds a new one. The relay only has to ignore the WebSocket > Close frame and keep the TCP connection open. It sends no malformed > data. The endpoint is in its default configuration and reaches the > attacker's relay when the application dials an address that names > it, for example from a ticket or from the address lookup of an > endpoint id the attacker controls. An endpoint that only accepts > connections cannot be steered there this way. > > The bug is at the end of `ActiveRelayActor::run_connected` in > `iroh/src/socket/transports/relay/actor.rs` (line 706–707). It > awaits `client_sink.close()` with no timeout and without serving its > priority inbox. Since the move to tokio-websockets, that future > resolves only when the server ends the stream. A non-home relay's > actor reaches this close after 60 s without outgoing datagrams, and > then sits alive but no longer reading its inboxes. </details> - [x] Self-review. - [x] Documentation updates following the [style guide], if relevant. - [x] Tests if relevant. - [x] All API changes documented. - [x] `cargo make` passes locally. [style guide]: https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text (cherry picked from commit 4a9c834d025d160b6dd843d3d316af40d46f7b88)
less net work for networks
What is iroh?
Iroh gives you an API for dialing by public key. You say “connect to that phone”, iroh will find & maintain the fastest connection for you, regardless of where it is.
Hole-punching
The fastest route is a direct connection, so if necessary, iroh tries to hole-punch. Should this fail, it can fall back to an open ecosystem of public relay servers. To ensure these connections are as fast as possible, we continuously measure iroh.
Built on QUIC
Iroh uses noq to establish QUIC connections between endpoints. This way you get authenticated encryption, concurrent streams with stream priorities, a datagram transport and avoid head-of-line-blocking out of the box.
Compose Protocols
Use pre-existing protocols built on iroh instead of writing your own:
- iroh-blobs for BLAKE3-based content-addressed blob transfer scaling from kilobytes to terabytes
- iroh-gossip for establishing publish-subscribe overlay networks that scale, requiring only resources that your average phone can handle
- iroh-docs for an eventually-consistent key-value store of iroh-blobs blobs
Getting Started
Rust Library
It's easiest to use iroh from rust.
Install it using cargo add iroh, then on the connecting side:
const ALPN: &[u8] = b"iroh-example/echo/0";
let endpoint = Endpoint::bind().await?;
// Open a connection to the accepting endpoint
let conn = endpoint.connect(addr, ALPN).await?;
// Open a bidirectional QUIC stream
let (mut send, mut recv) = conn.open_bi().await?;
// Send some data to be echoed
send.write_all(b"Hello, world!").await?;
send.finish()?;
// Receive the echo
let response = recv.read_to_end(1000).await?;
assert_eq!(&response, b"Hello, world!");
// As the side receiving the last application data - say goodbye
conn.close(0u32.into(), b"bye!");
// Close the endpoint and all its connections
endpoint.close().await;
And on the accepting side:
let endpoint = Endpoint::bind().await?;
let router = Router::builder(endpoint)
.accept(ALPN.to_vec(), Arc::new(Echo))
.spawn()
.await?;
// The protocol definition:
#[derive(Debug, Clone)]
struct Echo;
impl ProtocolHandler for Echo {
async fn accept(&self, connection: Connection) -> Result<()> {
let (mut send, mut recv) = connection.accept_bi().await?;
// Echo any bytes received back directly.
let bytes_sent = tokio::io::copy(&mut recv, &mut send).await?;
send.finish()?;
connection.closed().await;
Ok(())
}
}
The full example code with more comments can be found at echo.rs.
Or use one of the pre-existing protocols, e.g. iroh-blobs or iroh-gossip.
Other Languages
If you want to use iroh from other languages, make sure to check out iroh-ffi, the repository for FFI bindings.
Links
Repository Structure
This repository contains a workspace of crates:
iroh: The core library for hole-punching & communicating with relays.iroh-relay: The relay client and server implementation. This is the code we run in production for the public relays (and you can, too!).iroh-base: Common types likeEndpointIdorRelayUrl.iroh-dns-server: DNS server implementation powering the DNS/Pkarr address lookup for EndpointIds, running at dns.iroh.link.
License
Copyright 2025 N0, INC.
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.