Skip to content
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

Re-using the cURL handle breaks all but the first request #35

Closed
xrstf opened this issue Nov 12, 2014 · 10 comments
Closed

Re-using the cURL handle breaks all but the first request #35

xrstf opened this issue Nov 12, 2014 · 10 comments
Assignees
Labels

Comments

@xrstf
Copy link

xrstf commented Nov 12, 2014

I am using SabreDAV 2.0.5 with Sabre HTTP 2.0.4 on PHP 5.6 (Win x64). This is my test code, which should just check if a file exists (expected to 404) and then create it:

require 'vendor/autoload.php';

$client = new Sabre\DAV\Client(array(
    'baseUri' => 'http://my.webdav.host/',
    'proxy'   => 'http://127.0.0.1:8888/'   // for debugging with Fiddler
));

$client->request('HEAD', '/foo.txt'); // throws NotFound exception, as expected
$client->request('PUT', '/foo.txt', 'my content');

We are -- for testing -- tunneling WebDAV through nginx. Unexpectedly, we get an HTTP 500 for the PUT request, because it looks like this in Fiddler

PUT http://my.webdav.host/foo.txt HTTP/1.1
Host: my.webdav.host
Accept: */*
Connection: Keep-Alive

There is no content and no Content-Length header, making the nginx barf.

I traced the problem down to the Sabre\HTTP\Client class and its recycling of the cURL handle.

protected function doRequest(RequestInterface $request) {

    $settings = $this->createCurlSettingsArray($request);

    if (!$this->curlHandle) {
        $this->curlHandle = curl_init();
    }

    // ...snip...
}

If I disable the if and always recreate a new cURL handle, everything works as expected.

Since the curlHandle is private, I have very little chance to work around this except creating a new SabreDAV client for every single request.

@evert
Copy link
Member

evert commented Nov 12, 2014

Weird!

@Hywan
Copy link
Member

Hywan commented Nov 12, 2014

@xrstf What is your version of cURL please?

@xrstf
Copy link
Author

xrstf commented Nov 12, 2014

I'm using PHP 5.6.1:

cURL support     => enabled
cURL Information => 7.38.0
Age              => 3
AsynchDNS        => Yes
CharConv         => No
Debug            => No
GSS-Negotiate    => No
IDN              => Yes
IPv6             => Yes
krb4             => No
Largefile        => Yes
libz             => Yes
NTLM             => Yes
NTLMWB           => No
SPNEGO           => Yes
SSL              => Yes
SSPI             => Yes
TLS-SRP          => No
Protocols        => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Host             => i386-pc-win32
SSL Version      => OpenSSL/1.0.1i
ZLib Version     => 1.2.7.3
libSSH Version   => libssh2/1.4.3

@Hywan Hywan added the bug label Nov 12, 2014
@Hywan
Copy link
Member

Hywan commented Jan 12, 2015

@xrstf If you add the CURLOPT_FORBID_REUSE or CURLOPT_FRESH_CONNECT constants, does it solve your issue?

@evert
Copy link
Member

evert commented Jan 12, 2015

@Hywan even if that solved his issue, I think the most important thing is that we attempt to reproduce this and figure out why it's happening in the first place. On my machine, this is definitely not a problem...

@Hywan
Copy link
Member

Hywan commented Jan 12, 2015

@evert I am not able to reproduce the bug neither, that's why I was asking @xrstf to see if these options should solve the problem at first. If no, I will dig deeper.

@andreaswolf
Copy link

I can reproduce this with 4.0.0-alpha1. It is fixed on most recent master, but sabre/dav still uses 4.0.0-alpha1. Adding the following to composer.json updates sabre/http to master instead:

"require": {
  "sabre/http": "dev-master as 4.0.0-alpha1"
}

I’m using PHP 5.5.24 on Fedora 20 (cURL 7.32.0). As some people reported not being able to reproduce this: If you have anything I can do to help testing this, just contact me (here or via mail).

@evert
Copy link
Member

evert commented May 18, 2015

Hi Andreas,

I'm releasing 4.0.0-alpha2 right now to solve this.

@evert
Copy link
Member

evert commented May 18, 2015

Oh my I never realized this was the same ticket as #47 :(

On the bright side, the unittests are now changed to catch issues similar to this. I'm very sorry you had to wait this long.

@evert evert self-assigned this May 18, 2015
@evert
Copy link
Member

evert commented May 18, 2015

Just released the second alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants