Skip to content

Don't silently reattach a share to a different process after port reuse - #5

Open
AadhilFarhan wants to merge 1 commit into
mainfrom
fix/relay-stale-reattachment
Open

Don't silently reattach a share to a different process after port reuse#5
AadhilFarhan wants to merge 1 commit into
mainfrom
fix/relay-stale-reattachment

Conversation

@AadhilFarhan

Copy link
Copy Markdown
Owner

What

shares/relays were keyed by port only. The review flagged this scenario: a shared process dies, and a different, unrelated process binds the same port before the next 3-second poll's cleanup runs — the old cleanup check was just "is this port still live," which is still true, so the stale relay/share survived and kept exposing whatever now occupies that port. The row's "sharing" badge silently reattaches to a process the user never opted to share.

Fix

Added sharedPIDs: [Int: Int32], recorded at share time for both the relayed and direct-URL (allInterfaces) cases. The cleanup pass in refresh() now tears a share down whenever the port's live occupant no longer matches the pid it was originally shared for — not only when the port goes fully quiet.

While in this code I also noticed the original cleanup loop only ever iterated relays, so a direct (non-relayed, allInterfaces) share's shares[port] entry was never cleaned up at all when that server died — no relay existed to trigger the loop. Folded that into the same fix since it's the same cleanup logic and the same class of bug (stale share state), rather than opening a fourth PR for one adjacent line.

Test plan

  • Build succeeds.
  • Full suite: 9/9 passing (hygiene check — AppModel isn't covered by the existing test suite, consistent with the rest of the UI/state layer in this codebase; the actual timing race requires driving the live UI against real process churn on a real port within a 3s window, which isn't something I can automate in this session).
  • Worth a manual check before merging: share a server, kill it, immediately start something else on the same port, wait ~3s, confirm the share/badge clears instead of reattaching.

shares/relays were keyed by port only. If a shared process died and a
different, unrelated process bound the same port before the next 3s
poll's cleanup ran, the stale relay/direct-share entry survived (the
cleanup check was just "is this port still live") and kept exposing
whatever now occupied that port — a process the user never chose to
share, with the row's "sharing" badge silently reattaching to it.

Now tracks the pid a share was started for (sharedPIDs, covering both
the relayed and direct-URL cases) and tears the share down whenever
the port's live occupant no longer matches, not just when the port
goes fully quiet.
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.

1 participant