Skip to content

fix(relay): don't drop pending reservation accept/deny futures - #6655

Open
0xShadowX wants to merge 15 commits into
libp2p:masterfrom
0xShadowX:relay-reservation-futures
Open

0xShadowX wants to merge 15 commits into
libp2p:masterfrom
0xShadowX:relay-reservation-futures

Conversation

@0xShadowX

Copy link
Copy Markdown
Contributor

Related to #6141 (ReservationReqAccepted not always emitted, while the relay still routes circuits to the peer).

The relay server handler stores the response to an inbound reservation request in a single Option<ReservationRequestFuture>. When AcceptReservationReq or DenyReservationReq arrives while another one is still pending, the old future is replaced and only "Dropping existing deny/accept future in favor of new one" is logged. If the dropped one was an accept:

  • the behaviour has already put the connection into its reservations as active,
  • the handler never sets active_reservation, so there is no expiry for it,
  • no ReservationReqAccepted event is emitted and the client never receives the response, so its listener doesn't come up,
  • the reservation still counts toward max_reservations and circuits to the peer are routed.

That matches what #6141 describes. It happens deterministically when a client sends two reservation requests on the same connection and the second is denied (for example by the per-peer rate limiter), because the connection task handles both commands before polling the handler again.

The handler now keeps accept and deny futures in a FuturesUnordered and reports every result, same as it already does for circuit accept/deny.

Test:

cargo test -p libp2p-relay --test lib concurrent_reservation_requests_on_same_connection

Two listen_on calls to the same relay with a per-peer reservation rate of 1. On master the relay reports the denial but never the acceptance (accepted reservation request was dropped: left 0, right 1).

relay 0.22.0 is released, bumped to 0.22.1.

  • test fails on master, passes with the fix
  • changelog entry
  • cargo test -p libp2p-relay and -p libp2p-dcutr pass

The relay handler kept a single `reservation_request_future` and replaced
it when the behaviour sent another accept/deny for the same connection.
If an accept was replaced before it completed, the behaviour had already
marked the reservation as active but the handler never started the
reservation timer or reported `ReservationReqAccepted`, and the client
never got its response.

Keep all accept/deny futures in a `FuturesUnordered` and report each one.
@mergify

mergify Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @0xShadowX? 🙏

@mergify

mergify Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @0xShadowX? 🙏

@mergify

mergify Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @0xShadowX? 🙏

@mergify

mergify Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @0xShadowX? 🙏

@mergify

mergify Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @0xShadowX? 🙏

@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

@jxs jxs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR and sorry for the delay reviewing it.
overall LGTM but It needs two things though:

  1. A timeout. Switch the field to futures_bounded::FuturesSet with STREAM_TIMEOUT, exactly as inbound_workers already does (handler.rs:405-407). Without it, a peer that stalls the response write pins its substream until connection teardown, with no self-healing.

  2. A max_pending_reservations (per-connection) cap. FuturesSet gives you capacity + timeout in one construct, so this comes along with 1.
    At capacity, don't silently drop, that reintroduces #6141, instead emit ReservationReqAcceptFailed.

@0xShadowX

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Pushed 1df6c41: the reservation futures are now a futures_bounded::FuturesSet with STREAM_TIMEOUT, capped at 10 per connection. Over the cap, the handler emits ReservationReqAcceptFailed (or ReservationReqDenyFailed for a deny) instead of dropping silently. A timed-out response is reported as ReservationReqAcceptFailed, since the set doesn't keep which kind it was. Added two inbound_hop::Error variants for these cases and updated the changelog.

@mergify

mergify Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @0xShadowX? 🙏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants