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
SSH2 exec crashes while returning data & "Please close the channel (1) before trying to open it again" #1985
Comments
reopened from #1936. |
If you could post code that reproduces the problem and the logs (which you can get by doing
If the server hasn't ended the last If you opened a PTY before running the command then you can close the channel by doing This wouldn't be as big of an issue if phpseclib supported multiple channels better but that's years away. It'd require a fairly comprehensive rewrite of SSH2.php and right now, for phpseclib 4.0, I'm in the middle of a fairly comprehensive rewrite of ASN1.php / X509.php. |
What I do is, execute docker commands on a remote machine over a single connection. for example to restart a docker container:
Without enablePTY() this crashes the connection, but silently without any error. With enablePTY() the this or the next command complains with this issue's title. |
last debug entries before stop. This occurs during the first exec call "docker rm" <- NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION (since last: 0.0003, network: 0.0001s) -> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0003, network: 0s) <- NET_SSH2_MSG_CHANNEL_SUCCESS (since last: 0.0056, network: 0.0001s) -> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0002, network: 0s) <- NET_SSH2_MSG_CHANNEL_WINDOW_ADJUST (since last: 0.0069, network: 0.0002s) <- NET_SSH2_MSG_CHANNEL_SUCCESS (since last: 0.0002, network: 0.0001s) throws exception: "Please close the channel (1) before trying to open it again" |
I assume this means that you're doing this?: $ssh->enablePTY();
$ssh->exec('docker stop & rm');
$ssh->exec('docker run ...'); Anyway, as I said, that's not going to work and there's nothing I can easily do about that. I have designs to make that work better in phpseclib 5 but given that phpseclib 4 is prob years away from being released, clearly, phpseclib 5 is even farther away. You can do If you're going to do that you might as well use an interactive shell. Like read the prompt, send the command, read the prompt, and then send the next command. If you're not sure how to use that then https://phpseclib.com/docs/commands#read-with-regular-expressions-sudo should hopefully provide a good guide, however, you will need to figure out what your prompt is. Anyway, the SSH logs that'd be useful to see would be the one where it "crashes the connection, but silently without any error". The SSH logs and, if you can get them, the server logs. |
The crash is not logged. I can only tell it crashes, because pulling the docker image locally takes about a minute. SSH2:exec returns after 10 seconds without any output. |
I would say there is some overflow, maybe of a network buffer capturing the output. Since the docker progress bars send lots of text, could this be crashing exec()? |
Sounds like you're hitting the timeout. By default it's 10 seconds. You can make it so that it doesn't time out all together by doing That said, even if nothing is returned, you can still do define('NET_SSH2_LOGGING', 2);
$ssh = new SSH2('whatever.com');
$ssh->login('user', 'pass');
echo $ssh->getLog();
|
Thank you, The timeout() was the right solution to prevent the aborts. |
I am trying to trigger a docker download over a SSH connections on a remote server.
When calling the docker command locally, the images are downloaded. Doing that over SSH2, the output seems to confuse phpseclib and forces it to abort the connection without any returned result.
Moreover, the next exec statements raises the "Please close the channel (1) before trying to open it again" exception, showing, that the former exec() didn't finish correctly.
Base on an earlier bug report I included a
call before the exec command. This doesn't help.
The text was updated successfully, but these errors were encountered: