Skip to content

fix(tunnel:single): Windows port type error and stuck state#89

Merged
miguelsanchez-upsun merged 1 commit into
mainfrom
fix/tunnel-single-windows
May 26, 2026
Merged

fix(tunnel:single): Windows port type error and stuck state#89
miguelsanchez-upsun merged 1 commit into
mainfrom
fix/tunnel-single-windows

Conversation

@pjcdawkins
Copy link
Copy Markdown
Contributor

Summary

Two bugs reported against upsun tunnel:single on Windows in CLI 5.10.4:

1. --port causes a fatal TypeError.
InputOption::VALUE_REQUIRED returns the value as a string, but TunnelManager::create() is typed ?int, so upsun tunnel:single --port 30005 crashed with:

TunnelManager::create(): Argument #3 ($localPort) must be of type ?int, string given

Now the option is validated as a string (the validators accept int|string) and cast to int before being passed on.

2. Tunnel state gets stuck after the first run.
The persistent state in tunnel-info.json is cleaned up via posix_kill($pid, 0), which doesn't exist on Windows. So once a tunnel was recorded, the entry was never removed, and the next tunnel:single exited with "A tunnel is already opened" forever.

Since tunnel:single runs in the foreground on Windows (the background tunnel:open is explicitly disabled there), the persistent state isn't really useful — tunnel:list/info/close only make sense when the tunnel command has already returned. The fix skips both the isOpen() check and saveNewTunnel() on Windows, so no state is written and there's nothing to get stuck.

Existing stale entries in users' tunnel-info.json become harmless after this change — they're never read by tunnel:single on Windows.

The --port option arrives as a string from Symfony Console, but
TunnelManager::create() is typed ?int, causing a fatal TypeError when
the flag is used. Validate the string and cast to int before passing
it on.

The persistent tunnel state tracked in tunnel-info.json only cleans
up dead PIDs via posix_kill, which does not exist on Windows. The
first tunnel opened was therefore recorded as "still open" forever
and subsequent runs exited with "A tunnel is already opened". Since
tunnel:single runs in the foreground on Windows (no background
tunnels are supported there), skip both the isOpen() check and
saveNewTunnel() on Windows so no persistent state is written.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 26, 2026 14:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes two Windows-specific bugs in upsun tunnel:single: a TypeError caused by passing the string --port value to a strictly-typed ?int parameter, and a stuck "tunnel already opened" state caused by posix_kill() being unavailable on Windows (so stale entries in tunnel-info.json were never cleaned up).

Changes:

  • Read the --port option into a separate variable, validate it as int|string, and cast to int before passing to TunnelManager::create().
  • Skip isOpen() and saveNewTunnel() on Windows via a new $trackState flag, since persistent state can't be cleaned up there and tunnel:single runs in the foreground anyway.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@miguelsanchez-upsun miguelsanchez-upsun merged commit 6cd4713 into main May 26, 2026
5 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.

3 participants