php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74816 Multiple ssh2-sftp connections will all point to the first one
Submitted: 2017-06-26 15:57 UTC Modified: 2021-02-21 04:22 UTC
From: andreas dot buchenrieder at check24 dot de Assigned: cmb (profile)
Status: No Feedback Package: ssh2 (PECL)
PHP Version: 7.1.6 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andreas dot buchenrieder at check24 dot de
New email:
PHP Version: OS:

 

 [2017-06-26 15:57 UTC] andreas dot buchenrieder at check24 dot de
Description:
------------
PHP-Version: 7.1.6-2+0~20170614060700.1+jessie~1.gbp831871

I open multiple ssh2 connections in a loop. In my case the server itself is always the same, but the username/password changes. So I cannot say if this error happens if the server changes as well

Basically each file should be put on a different account
With opcache enabled, every file is uploaded on the first connection, even though it should always be a new one. The streams meta data even shows a new resource id for each connection

This does not happen in PHP 5.6 or with opcache disabled

Test script:
---------------
<?php

$configs = [
    ['host', 'username', 'password', '/path/'],
    // ...
];

while (true) {
    $index = array_rand($configs);
    list($host, $username, $password, $path) = $configs[$index];
    $port = 22;
    $connection = ssh2_connect($host, 22);
    if ($connection === false) {
        continue;
    }
    if (!ssh2_auth_password($connection, $username, $password)) {
        continue;
    }
    $sftp = ssh2_sftp($connection);
    $handle = @fopen('ssh2.sftp://' . intval($sftp) . $path . $username, 'w+');
    if ($handle === false) {
        continue;
    }
    print_r(stream_get_meta_data($handle));
    fclose($handle);
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-26 20:15 UTC] langemeijer@php.net
-Package: opcache +Package: ssh2
 [2017-06-26 21:24 UTC] mhagstrand at gmail dot com
This appears to be a duplicate of https://bugs.php.net/bug.php?id=74667
 [2017-06-27 14:43 UTC] andreas dot buchenrieder at check24 dot de
I just checked and it seems I was wrong about suspecting opcache to be the reason.
The error persists even if opcache is not even loaded

So much for a workaround :(
 [2017-06-27 15:20 UTC] andreas dot buchenrieder at check24 dot de
I think I localized the issue.

The test script provided is missing the key point. I kept the once opened sftp resources in an array to save the costs of reconnecting again and again

So somewhere in my script was a line like $pool["$username@$host"] = $sftp;

By keeping the resource in an array outside the loop the error occurred, even if I never reused the cached connection. If I keep only the ssh connection and reinstantiate the sftp resource new every time, the error disappeared.
 [2021-02-10 16:13 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-02-10 16:13 UTC] cmb@php.net
This is likely a duplicate of bug #72988, which is fixed as of
ssh2 1.1.  Or can you still reproduce this issue?
 [2021-02-21 04:22 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Aug 04 10:01:23 2021 UTC