Partial hang fix from #520 breaks proxy sockets #774

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

Projects

None yet

2 participants

@bitprophet
Member

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
Member

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

@bitprophet bitprophet added a commit that referenced this issue Jul 26, 2016
@bitprophet bitprophet Changelog closes #774 c0c0dff
@bitprophet
Member

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

@nvgoldin

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
Member

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