Skip to content

Fix infinite loop when proxy command dies - #1180

Open
vincentbernat wants to merge 1 commit into
paramiko:mainfrom
vincentbernat:fix/proxy-infinite-loop
Open

vincentbernat wants to merge 1 commit into
paramiko:mainfrom
vincentbernat:fix/proxy-infinite-loop

Conversation

@vincentbernat

Copy link
Copy Markdown

When proxy command dies, reading from the file descriptor returns an
empty string. From documentation, this is the expected way to signal
an end-of-file for this file descriptor (no exception is raised). If
we have something in the buffer, let's give it back, otherwise,
trigger an exception.

@ploxiln

ploxiln commented Mar 26, 2018

Copy link
Copy Markdown
Contributor

see also #963

@ploxiln

ploxiln commented Mar 26, 2018

Copy link
Copy Markdown
Contributor

nevermind, I see you've seen that PR :) this does look better

@nbartos

nbartos commented May 27, 2018

Copy link
Copy Markdown

@vincentbernat This does look better than my old PR #963, I just closed it. It looks like you may need to write a test to get it merged, the code coverage checks are complaining.

@nbartos

nbartos commented Aug 16, 2018

Copy link
Copy Markdown

@vincentbernat Would you mind resolving the merge conflicts and coverage test failures? It would be really great to get this merged in.

@vincentbernat
vincentbernat force-pushed the fix/proxy-infinite-loop branch from bed78d1 to 5b12f94 Compare August 17, 2018 05:27
@vincentbernat

Copy link
Copy Markdown
Author

I have rebased on master.

Comment thread paramiko/proxy.py Outdated
if not b:
if buffer:
return buffer
raise ProxyCommandFailure(' '.join(self.cmd),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying out this code, it looks like this exception is always getting raised (paramiko==2.4.1) after a command successfully exits. I think this should be:

                if r and r[0] == self.process.stdout:
                    b = os.read(self.process.stdout.fileno(), size - len(buffer))
                    if not b:
                        return buffer
                    buffer += b
            return buffer

@vincentbernat
vincentbernat force-pushed the fix/proxy-infinite-loop branch from 5b12f94 to 474de34 Compare August 17, 2018 06:03
@vincentbernat

Copy link
Copy Markdown
Author

I have updated the PR with your suggestion.

@nbartos

nbartos commented Aug 17, 2018

Copy link
Copy Markdown

Looks like the python 3.6 gate wants a line length change:

-                        self.process.stdout.fileno(), size - len(buffer))
+                        self.process.stdout.fileno(), size - len(buffer)
+                    )

When proxy command dies, reading from the file descriptor returns an
empty string. From documentation, this is the expected way to signal
an end-of-file for this file descriptor (no exception is raised). If
we have something in the buffer, let's give it back, otherwise,
trigger an exception.
@vincentbernat
vincentbernat force-pushed the fix/proxy-infinite-loop branch from 474de34 to d59ac55 Compare August 17, 2018 06:26
@vincentbernat

Copy link
Copy Markdown
Author

OK, this should be fixed.

@nbartos

nbartos commented Aug 21, 2018

Copy link
Copy Markdown

@ploxiln I don't suppose you know who we should ping to try and get this merged?

@ploxiln

ploxiln commented Aug 21, 2018

Copy link
Copy Markdown
Contributor

@bitprophet

@bitprophet

Copy link
Copy Markdown
Member

It'd be sweet if we could whip up some tests for this, but I'll probably only be a stickler about that if there are existing tests for this functionality that can be easily extended. I've put it in the next bugfix milestone. No ETA.

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.

4 participants