Skip to content

Commit

Permalink
Issue paramiko#537 reproduction test and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rusek committed Feb 11, 2016
1 parent e3b11da commit 306b24d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 9 additions & 5 deletions paramiko/buffered_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ def set_event(self, event):
:param threading.Event event: the event to set/clear
"""
self._event = event
if len(self._buffer) > 0:
event.set()
else:
event.clear()
self._lock.acquire()
try:
self._event = event
if self._closed or len(self._buffer) > 0:
event.set()
else:
event.clear()
finally:
self._lock.release()

def feed(self, data):
"""
Expand Down
18 changes: 18 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,21 @@ def test_L_handshake_timeout(self):
hostkey=public_host_key,
username='slowdive',
password='pygmalion')

def test_M_select_after_close(self):
"""
verify that select works when a channel is already closed.
"""
self.setup_test_server()
chan = self.tc.open_session()
chan.invoke_shell()
schan = self.ts.accept(1.0)
schan.close()

# give client a moment to receive close notification
time.sleep(0.1)

r, w, e = select.select([chan], [], [], 0.1)
self.assertEqual([chan], r)
self.assertEqual([], w)
self.assertEqual([], e)

0 comments on commit 306b24d

Please sign in to comment.