Skip to content

[Bug]: remote messaging releases its forward port candidate before SSH binds it #7845

Closed

Description

@lidge-jun

Client or integration

Other

Area

Other

Summary

Remote messaging setup picks a local forward port with remotePortCandidate() (src/messaging/remote-ports.ts). That function binds port 0, reads the number and releases the listener; the port is bound again later by number. In src/messaging/remote-tunnels.ts (around line 27) and src/cli/message-remote-command.ts (around line 60), SSH binds the released candidate afterwards. Between release and bind, another process (or a second candidate selection in the same process) can take the port, so tunnel setup fails or targets a port shared with another listener. Bun binds a second listener on an occupied port without EADDRINUSE unless exclusive is set, so the collision is not always reported as a bind error.

The test fixture form of this race caused #7809 and is fixed in #7820. This issue tracks the product paths. Authenticated readiness still prevents talking to the wrong peer, so the impact is availability (setup failure), not identity.

Expected: keep the port reserved until SSH takes it over, or detect a lost candidate and reselect within a bounded number of attempts, without weakening authenticated readiness.

Reproduction

Not reproduced in the product. Found while reviewing #7820. In the fixture, 50,000 adjacent candidate pairs produced 3 to 10 duplicates on Linux.

Version

dev (2.94.0 line)

Operating system

Linux / macOS (remote messaging transport)

Provider and model

No response

Logs or error output

n/a

Screenshots and supporting files

No response

Redacted configuration

n/a

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

  1. added
    bug
    on Oct 27, 2026
  2. Ingwannu commented on Oct 29, 2026

    @Ingwannu
    Owner

    Closing as completed on dev: #7893 merged as 69c1c6ed6bc7779fedb50734d42a96f72daf6ffd, which I verified is an ancestor of current trusted dev 9b78a16f4fe0c300527e6b183052407269bb941d.

    Remote messaging holds exclusive port reservations until SSH handoff, recognizes an explicit lost-forward signal, and retries at most three times without weakening authenticated readiness.

    I checked the implementation and the successful exact-head required CI for 1ef9557599b31e0cd501439674e8c2b816fc11b0. Existing author regression receipts remain author-run evidence; I did not rerun unchanged passing suites or reproduce this on a live account/native client. This closure records the landed scope, not validation of the reporter's installed version or a release claim. If the same failure occurs on a build containing this commit, provide a new bounded, redacted reproduction against that build.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions