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

Client connection becomes stale after long periods of time. #225

Closed
warroyo opened this issue Apr 23, 2015 · 6 comments
Closed

Client connection becomes stale after long periods of time. #225

warroyo opened this issue Apr 23, 2015 · 6 comments

Comments

@warroyo
Copy link

warroyo commented Apr 23, 2015

I have a long running background job and I am making calls to ES at different points throughout the job to update fields in ES. After not calling ES for about 8 minutes and trying to make a call though the client again it will just hang. I do not receive any exceptions or timeout. it just hangs. is there a reason this could be happening? Does the client connection persist the whole time my job is running from the initial instantiation? is there a way to reconnect?

UPDATE:
I have found this to be a problem with my load balancer that ES is behind, it kills tcp connections after 5 minutes. the problem is that my persistent connection does not register the connection being closed so it just hangs. Is there a way to reset the connection? or have the client ping every 60 seconds?

@polyfractal
Copy link
Contributor

Hmm, interesting. If the socket doesn't drop cleanly (e.g. half-open socket), it's possible the curl handles will just hang...although they should timeout eventually. I'm surprised you don't see a timeout at all. I'll try to setup some tests to see why this is the case.

As mentioned in #226, you can tell curl to explicitly close connections after each use by using CURLOPT_FORBID_REUSE. Pinging every 60 seconds would also be a viable option to keep the socket open and avoid the cost of tearing it down after every API call.

@warroyo
Copy link
Author

warroyo commented Apr 24, 2015

I attempted to set the the following options but it did not timeout. I ended up having my code create a new instance of the Client for every connection( I am not making that many requests so it is not a big deal, only about 10 requests over a 20 minute period). I just added the CURLOPT_FORBID_REUSE, and now the connections will close immediately which is a big help.

I would still be interested int he results form your tests though.

'guzzleOptions' => array(
        'curl.options'=> array(CURLOPT_CONNECTTIMEOUT=> 2.0)
      )

@polyfractal
Copy link
Contributor

Agreed, it's quite odd. I wonder if it is a limitation of libcurl perhaps? Not sure, will need to dig into it next week with proper testing. I'll update this thread when I have more news :)

@polyfractal
Copy link
Contributor

Closing, this is likely no longer relevant since we're not on that version of guzzle anymore :)

@asanovr
Copy link

asanovr commented Jul 13, 2018

How i can tell curl use CURLOPT_FORBID_REUSE in latest client version ? I can't find it in docs

@polyfractal
Copy link
Contributor

Arbitrary curl options go inside ['client']['curl'] on the request. This is an indexing request example, but it works for any kind of request:

    $params = [
        'index' => 'posts',
        'type' => 'tags',
        'id' => 24,
        'client' => [
            'curl' => [
                CURLOPT_FORBID_REUSE => true // <-- here
            ]
        ]
    ];

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

No branches or pull requests

3 participants