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

Partial hang fix from #520 breaks proxy sockets #774

Closed
bitprophet opened this Issue Jul 14, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@bitprophet
Member

bitprophet commented Jul 14, 2016

An anonymous user noted via email that the partial fix committed earlier for #520 breaks on the "using a Channel as a proxy socket" use case (as seen eg via Fabric with env.gateway set - though I think this user was doing it independently of that).

Specifically, the issue happens because socket objects (under Py3) exhibit ._closed, but Channel objects exhibit .closed. Since the earlier fix branches into a test of sock._closed under Python 3, an AttributeError is raised:

  File "/opt/virtenv/3.5.2/lib/python3.5/site-packages/paramiko/client.py", line 394, in close
    self._transport.close()
  File "/opt/virtenv/3.5.2/lib/python3.5/site-packages/paramiko/transport.py", line 645, in close
    self.stop_thread()
  File "/opt/virtenv/3.5.2/lib/python3.5/site-packages/paramiko/transport.py", line 1550, in stop_thread
    and not self.sock._closed and not self.packetizer.closed
AttributeError: 'Channel' object has no attribute '_closed'

As this user suggests, I think a simple hasattr test added to the mix ought to suffice; this would also help with situations where socket.closed becomes a real API (ISTR confusion on this point during dev of the earlier fix anyways - but that was probably Python 2 vs 3.)

@bitprophet bitprophet added the Bug label Jul 14, 2016

@bitprophet bitprophet added this to the 1.16.3 et al milestone Jul 14, 2016

@bitprophet

This comment has been minimized.

Member

bitprophet commented Jul 26, 2016

Spliced gateway support into Fabric 2 & confirmed this myself under Python 3. Fix inbound.

bitprophet added a commit that referenced this issue Jul 26, 2016

@bitprophet

This comment has been minimized.

Member

bitprophet commented Jul 26, 2016

Turns out just updating Channel to expose both attributes was way more elegant than doing some hackneyed getattr stuff elsewhere.

@nvgoldin

This comment has been minimized.

nvgoldin commented Jul 30, 2016

Hi, after installing 2.0.2, I'm still getting the same error when using ProxyCommand:

traceback (most recent call last):
  File "testing.py", line 16, in <module>
    ssh.close()
  File "/home/ngoldin/virtualenv/python3.5/lib/python3.5/site-packages/paramiko/client.py", line 394, in close
    self._transport.close()
  File "/home/ngoldin/virtualenv/python3.5/lib/python3.5/site-packages/paramiko/transport.py", line 645, in close
    self.stop_thread()
  File "/home/ngoldin/virtualenv/python3.5/lib/python3.5/site-packages/paramiko/transport.py", line 1552, in stop_thread
    and not self.sock._closed and not self.packetizer.closed
AttributeError: 'ProxyCommand' object has no attribute '_closed'
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/home/ngoldin/virtualenv/python3.5/lib/python3.5/site-packages/paramiko/transport.py", line 77, in _join_lingering_threads
    thr.stop_thread()
  File "/home/ngoldin/virtualenv/python3.5/lib/python3.5/site-packages/paramiko/transport.py", line 1552, in stop_thread
    and not self.sock._closed and not self.packetizer.closed
AttributeError: 'ProxyCommand' object has no attribute '_closed'
@bitprophet

This comment has been minimized.

Member

bitprophet commented Jul 30, 2016

Well that'd be because ProxyCommand isn't Channel, so it never got the fix. Bah! Thanks for the report. Will make a new ticket & fix that real quick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment