Skip to content

Return the port the OS picked when opening local port 0 - #21

Merged
mfazekas merged 1 commit into
masterfrom
local-port-zero
Nov 9, 2026
Merged

mfazekas merged 1 commit into
masterfrom
local-port-zero

Conversation

@mfazekas

@mfazekas mfazekas commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

With local_port 0, open returned and yielded 0 instead of the port the OS bound, so the tunnel was unusable and close cancelled the wrong forward. Net::SSH::Service::Forward#local returns the bound port, so open now uses it. This lets several gateways in one process avoid clashing on the ports next_port picks. Based on #6 by @thechile, without its unrelated host? method; adds tests and was checked against a real sshd with two gateways.

Net::SSH::Service::Forward#local returns the bound port, so use it
instead of the requested one: with local_port 0, open now returns and
yields the real port and close cancels the right forward. Based on #6
by @thechile.
@mfazekas
mfazekas merged commit 16b33e5 into master Nov 9, 2026
10 checks passed
@mfazekas
mfazekas deleted the local-port-zero branch November 9, 2026 19:31
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