Subject: | $ssh->error does not seem to detect address in use |
Date: | Wed, 19 Aug 2020 09:48:57 -0700 |
To: | bug-Net-OpenSSH [...] rt.cpan.org |
From: | Andrew DeFaria <Andrew [...] DeFaria.com> |
For some reason Net::OpenSSH does not properly handle the case where the
address is in use. Shown here in the Perl debugger I first set a
breakpoint for line #79 and run to it. Next I continue to line #87. At
this point the ssh tunnel has been established and is up and running.
Now, to exhibit the problem, I again try to set up an exact duplicate of
the tunnel. I get "Address already in use" written to stderr but as you
can see $ssh2->error returns 0 as if there is no error. I'm trying to
catch the situation where the tunnel is already up.
78 sub exhibitBug() {
79==>b my $tunnelStr = "-NLlocalhost:1025:defaria.com:25";
80
81 # First establish the tunnel
82: my $ssh1 = Net::OpenSSH->new('defaria.com', master_opts =>
$tunnelStr);
83
84: $ssh1->error and die "Couldn't set up tunnel - " .
$ssh1->error;
85
86 # Now try to establish the tunnel again.
87: my $ssh2 = Net::OpenSSH->new('defaria.com', master_opts =>
$tunnelStr);
88
89: $ssh2->error and die "Couldn't set up tunnel - " .
$ssh2->error;
90
91 # No error is reported!
92: return;
93 }
DB<<7>> c 87
main::exhibitBug(tunnel.pl:87): my $ssh2 =
Net::OpenSSH->new('defaria.com', master_opts => $tunnelStr);
DB<<8>> # Now ssh tunnel is established
DB<<9>> c 89
bind [127.0.0.1]:1025: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 1025
Could not request local forwarding.
main::exhibitBug(tunnel.pl:89): $ssh2->error and die "Couldn't
set up tunnel - " . $ssh2->error;
DB<<10>> x $ssh2->error
0 0
DB<<11>>
What's worse is that multiple ssh sessions are established, even though
the address was in use!
Earth:ps -ef | grep '\-NL'
andrew 180966 180818 0 09:42 pts/2 00:00:00 ssh
-NLlocalhost:1025:defaria.com:25 -o ServerAliveInterval=30 -o
ControlPersist=no -2MNx -S
/home/andrew/.libnet-openssh-perl/ef9bb48494b15dfdeeffddee2b7253e4
defaria.com --
andrew 181006 180818 0 09:43 pts/2 00:00:00 ssh
-NLlocalhost:1025:defaria.com:25 -o ServerAliveInterval=30 -o
ControlPersist=no -2MNx -S
/home/andrew/.libnet-openssh-perl/46fd3cf2cb458d425e55b7de451c4e2a
defaria.com --
Earth:
Is there something I can do or set so that the second tunnel fails to
start another ssh session and returns some sort of error code in
$ssh->error?
--
Andrew DeFaria <http://defaria.com>
If a pig loses its voice, is it disgruntled?