Skip to content

Fix race condition between Channel.close() and other channel send met… - #1137

Open
yieldi wants to merge 1 commit into
paramiko:mainfrom
yieldi:master
Open

yieldi wants to merge 1 commit into
paramiko:mainfrom
yieldi:master

Conversation

@yieldi

@yieldi yieldi commented Dec 18, 2017

Copy link
Copy Markdown

…hods.

This is a fix for #1115 .

ploxiln added a commit to ploxiln/paramiko-ng that referenced this pull request Nov 26, 2021
While the channel tracks its state for generating messages under
its own lock, it needs to release that lock before calling the
transport method to send a message, which uses the transport's lock.
Messages could be generated under the correct conditions and in the
correct order, but then sent in a different order, if two different
threads are calling channel methods.

This was made much more likely by the recent addition of
ChannelStdinFile (in paramiko-ng 2.8.0) which calls shutdown_write()
automatically when closed. So, for now, protect only EOF to fix the
immediate regression, and reduce code churn. There is already a mess
of state checking of dubious robustness, e.g. the open_only()
decorator ...

This problem was well described in paramiko#1115 and this
solution is heavily inspired by paramiko#1137 so:

Co-Authored-By: Ryan <[email protected]>
ploxiln added a commit to ploxiln/paramiko-ng that referenced this pull request Nov 26, 2021
While the channel tracks its state for generating messages under
its own lock, it needs to release that lock before calling the
transport method to send a message, which uses the transport's lock.
Messages could be generated under the correct conditions and in the
correct order, but then sent in a different order, if two different
threads are calling channel methods.

(We need to release the channel lock to avoid deadlock during
re-keying according to commit 305f5e0.)

This was made much more likely by the recent addition of
ChannelStdinFile (in paramiko-ng 2.8.0) which calls shutdown_write()
automatically when closed. So, for now, protect only EOF to fix the
immediate regression, and reduce code churn. There is already a mess
of state checking of dubious robustness, e.g. the open_only()
decorator ...

This problem was well described in paramiko#1115 and this
solution is heavily inspired by paramiko#1137 so:

Co-Authored-By: Ryan <[email protected]>
@bskinn

bskinn commented Jun 25, 2023

Copy link
Copy Markdown
Contributor

Labeling as needs tests -- tests may or may not be practical, but they should be considered.

AlonMarko pushed a commit to AlonMarko/paramiko that referenced this pull request Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants