Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh "connect" event is not fired when connected after close() #23

Open
jeffrson opened this issue Feb 22, 2019 · 5 comments
Open

ssh "connect" event is not fired when connected after close() #23

jeffrson opened this issue Feb 22, 2019 · 5 comments

Comments

@jeffrson
Copy link
Contributor

jeffrson commented Feb 22, 2019

Here is a short test:

let sshconfig = {
  host: '192.168.1.1',
  port: 22,
  username: 'test',
  password: 'test',
  reconnect: false
}

let ssh = new SSH2Promise(sshconfig)
ssh.on('ssh', (...args) => console.log(args[0]))

let sftp = ssh.sftp()

sftp.readdir('/home/test')
  .then((data) => console.dir('data'))
  .then(() => ssh.close())
  .then(() => ssh.connect())
  .then(() => sftp.readdir('/home/test'))
  .then((data) => console.dir('next try'))

it results in

beforeconnect
connect
connect
'data'
beforedisconnect
disconnect
beforedisconnect
'next try'

As you can see, there's no 'connect' after close. Furthermore, two 'connect' on the first try seem strange as well as the second 'beforedisconnect' after 'disconnect'.

@jeffrson
Copy link
Contributor Author

BTW, I believe this is somehow related to 'ssh.close()' not really closing when called after connected the second time.

That's why I hesitate to report this fact as a new bug. What do you think?

@jeffrson
Copy link
Contributor Author

jeffrson commented Feb 27, 2019

There is a problem when closing the connection - the array deregister is not cleared (or otherwise modified) upon close.

Then, in getSSHConnection, the newly created sshConnection is not registered at all, because isRegistered thinks, the connection had already been registered, because the "unique id" has not changed.

@sanketbajoria
Would it be possible to fix it on short-term? I see three alternative solutions:

  1. clear the array in SSH2Promise.close()
  2. remove the element in disconnectCb
  3. forcibly re-register in getSSHConnection, as soon as a new sshConnection is created.

This doesn't fix the strange sequence of "beforedisconnect", though.

@sanketbajoria
Copy link
Owner

@jeffrson
Thanks for reporting this. I will look into this. If you do find a solution. Please feel free to raise a PR

@oscarrobinson
Copy link

Is a fix for this coming? I've observed lots of weird behaviour around reconnects that seems to be related to the issues described here.

@dobby-tgc
Copy link

Any updates yet?

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

No branches or pull requests

4 participants