zeromq / pyzmq

PyZMQ: Python bindings for zeromq
http://zguide.zeromq.org/py:all
BSD 3-Clause "New" or "Revised" License
3.65k stars 637 forks source link

BUG: `try_passwordless_ssh` hangs while connecting to server #1904

Closed KenyC closed 10 months ago

KenyC commented 10 months ago

What pyzmq version?

23.2.0

What libzmq version?

4.3.4

Python version (and how it was installed)

Python 3.9.13, from Anaconda

OS

Ubuntu 22.04

What happened?

The function try_passwordless_ssh should return False but instead, it hangs indefinitely.

Code to reproduce bug

import zmq.ssh

SERVER_IP = "123.123.123.123" 
KEY = "/path/to/my/key"
zmq.ssh.try_passwordless_ssh(SERVER_IP, KEY)
# Hangs there indefinitely

Traceback, if applicable

No response

More info

Came here from Helium sublime-text plugin which uses pyzmq under the hood. However, I was able to replicate it with Anaconda.

Related to #676, albeit not fixed by the fix proposed for that issue.

There seems to be 2 problems with the code for the function:

  1. try_passwordless_ssh has a while True: loop which always has potential to hang if the ssh command doesn't behave like pyzmq expects ; some max retry number should be added in there.
  2. My ssh program (shipped with Ubuntu 22.04) doesn't behave like pyzmq expects. It has the passphrase prompt below. By contrast, the _password_pat used in try_passwordless_ssh wants "passphrase" to be immediately followed by ":"
Enter passphrase for key '/path/to/my/key/`: 

I can beautify the hacky fix I have and submit it as a pull request.

minrk commented 10 months ago

A PR would be great!

KenyC commented 10 months ago

Ok I made the pull request. I don't know this code so I hope someone can check that it doesn't break anything.