[Ssh-sftp-perl-users] Bug causing too many open file descriptors
Brought to you by:
dbrobins
From: Sean S. <sst...@ya...> - 2008-03-13 21:50:46
|
Hello, I have a Perl script that opens a connection to numerous remote servers and runs several commands on each. In many cases, a server which has been connected to earlier during the script run will need to have more commands run on it. Therefore to make it more efficient, I keep a list of the open SSH connections and simply reuse those connections to run commands later when necessary. I noticed, though, that I sometimes run out of file descriptors. I did a truss and found that the problem is some "dup"s being done for the STDIN, STDOUT and STDERR every time the Net::SSH::Perl cmd() method is called. Digging into the Net::SSH::Perl code, I discovered that the cmd() method inside SSH2.pm in turn calls "$ssh->_session_channel". The method "_session_channel" contains the following code: my $channel = $cmgr->new_channel( ctype => 'session', local_window => 32*1024, local_maxpacket => 16*1024, remote_name => 'client-session', rfd => _dup('STDIN', '<'), wfd => _dup('STDOUT', '>'), efd => _dup('STDERR', '>')); I don't know much about SSH but I am surprised that a new channel is created every time a cmd is run. I would have thought you could reuse an open channel. But anyway, it's clear that 3 file descriptors are created every time cmd() is called, but I don't see any place where those file descriptors are being released. In the Channel.pm code, I see some comments suggesting that the author needs to go back and close file descriptors at various points (search for "XXX" in the Channel.pm code). It seems odd to me that a new channel is created every time cmd is run suggesting that open channels cannot be reused for some reason, yet there is no attempt to close those unusable open channels. I'm perfectly willing to do some kind of work around, like manually closing the open channels or disconnecting from the remote SSH server and then reconnecting (which hopefully closes the channels and releases all file descriptors associated with that connection), but I see no way to do that. There is a "login()" method for this module, but there is no "logout()" that I know of. Any advice on how to get around this problem would be sincerely appreciated. Thank you, Sean |