Skip to content

feat(net): handle browser sign-in connections concurrently - #112

Merged
AlxcBTW merged 2 commits into
anyplaynet:mainfrom
fogydes:feat/browser-concurrent-sign-in
Oct 27, 2026
Merged

AlxcBTW merged 2 commits into
anyplaynet:mainfrom
fogydes:feat/browser-concurrent-sign-in

Conversation

@fogydes

@fogydes fogydes commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Handles incoming browser sign-in connections concurrently in \crates/net/src/browser.rs.

  • Previously, \serve()\ sequentially awaited \handle()\ on accepted streams inside the accept loop. A preconnecting, slow, or stalled local connection could hold the loop for up to 5 seconds, delaying the actual redirect callback.
  • Connections are now spawned concurrently via \ okio::select!\ and an \mpsc\ completion channel, allowing stalled or extraneous requests to time out independently while the callback is delivered immediately.
  • Adds test \�_stalled_connection_does_not_block_the_callback\ verifying that a stalled connection on the loopback port does not delay the sign-in redirect.

Checklist

  • \cargo fmt --all -- --check, \cargo clippy --workspace --all-targets -- -D warnings\ and \cargo test --workspace\ pass.
  • New behaviour has a hermetic test (own servers on loopback, no internet, no game).
  • A change to a specification or a decision comes with an ADR in \docs/adr/.
  • A change to the bridge protocol (\spec/bridge-protocol.md, \crates/bridge-protocol) states its wire effect: the version, and whether the AnyPS5 fork has to change with it.
  • It works for every game. No title ID in code; what is known per title is in specifications and tests.
  • It stays on the right side of ADR 0021, and no game data is attached: no dumps, keys, firmware, saves, tokens, or logs with game memory.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@AlxcBTW AlxcBTW 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.

Thanks fago. Moving each connection to its own task fixes the stalled-connection block, and the test for it is good. Two things before merge:

  1. There is no bound on concurrent connections. Each task lives at most 5 seconds, but a local program can still open thousands in that time. Please add a small cap (a tokio::sync::Semaphore with about 16 permits, try_acquire_owned before spawning; over the cap, just drop the stream) and a test that the callback still works while the cap is full of stalled connections.
  2. When the sign-in finishes or times out, serve returns but spawned handlers keep running up to 5 s with the stream. Please hold the tasks in a JoinSet (or abort them on return) so they end with the sign-in.

The accept-error backoff and the loopback check are kept, good. Minor: put use std::sync::Arc; with the other std import at the top.

@fogydes

fogydes commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Updated per review in commit 72875a3:

  1. Bounded concurrency (\MAX_CONNECTIONS = 16): Added \ okio::sync::Semaphore\ with 16 permits; new connections over the cap are immediately dropped (\ ry_acquire_owned).
  2. **Lifecycle management via \AbortOnDrop(JoinSet)**: Connection tasks are held in a \JoinSet\ wrapped with \AbortOnDrop\ and joined incrementally in the select loop, and aborted upon returning the callback so handlers do not outlive sign-in or timeout.
  3. Tests:
    • Updated \�_stalled_connection_does_not_block_the_callback\ to hold \MAX_CONNECTIONS - 1\ stalled streams and verify the callback connects and finishes cleanly.
    • Added \connections_over_the_cap_are_dropped\ to assert incoming connections beyond 16 are dropped immediately and that releasing permits re-enables accepts.
  4. Cleaned up imports: Grouped \use std::sync::Arc;\ with std imports at the top.

@AlxcBTW AlxcBTW 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.

Thanks fago, the cap, the abort on return and the test with the cap nearly full all look right. Merging once CI is green.

@AlxcBTW
AlxcBTW merged commit ea35202 into anyplaynet:main Oct 27, 2026
12 of 14 checks passed
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