jnthn / p6-ssh-libssh

Asynchronous binding for libssh; client-only and limited functionality so far.
8 stars 8 forks source link

Hang on new connection to filtered port #13

Open Demayl opened 6 years ago

Demayl commented 6 years ago

This example hangs and eats 100% cpu when the connection times out in the OS. I think the problem is that event session must be removed after the timeout + ssh_free must be called in the CATCH phaser ( maybe teardown-session(), but then ssh_event_remove_session will fail with "Connection timeout" ). https://github.com/jnthn/p6-ssh-libssh/blob/926d72092eb9c9757f15f3095ecda45553193bc9/lib/SSH/LibSSH.pm6#L263-L274

Example:

#!/usr/bin/env perl6

use SSH::LibSSH;

CATCH { default { note "FAILED WITH $_"; sleep 60 } }
say "Connect";
my $sess = await SSH::LibSSH.connect( :host('8.8.8.8'), :user('root'), :port(2224) );
say "DONE - sleep 60";
sleep 60;
patrickbkr commented 2 years ago

I hit a similar (same?) problem. In my case I tried to connect to a non existing IP and the connect call seemed to hang indefinitely (>60 seconds). A look into the libssh sources reveals that the timeout option is ignored on the ssh_connect call when using non-blocking mode. This means that timeout handling has to happen client side, which currently doesn't happen.

jnthn commented 2 years ago

@patrickbkr Does the merge of #17 mean this is resolved?

patrickbkr commented 2 years ago

@jnthn That PR fixes my problem of hanging when the server is not reachable. I can't say for sure the problem @Demayl reported is actually the same.