keenlabs / KeenClient-PHP

Official PHP client for the Keen IO API. Build analytics features directly into your PHP apps.
https://keen.io/docs
MIT License
133 stars 57 forks source link

Repeated curl 35 error (TCP connection reset by peer) #82

Closed JakubMatejka closed 8 years ago

JakubMatejka commented 8 years ago

Hi,

We get one or two curl 35 errors a day and it starts to be unpleasant. Could you consider using some backoff and retry mechanism to prevent them? Guzzle 3.7 even has backoff strategy plugin which would catch it: https://github.com/guzzle/guzzle/blob/v3.7.4/src/Guzzle/Plugin/Backoff/CurlBackoffStrategy.php

The stacktrace looks like:

CurlException (0) in CurlMulti.php line 359:
[curl] 35: TCP connection reset by peer [url] https://api.keen.io/3.0/projects/.../events/load_data
in CurlMulti.php line 359
at CurlMulti->isCurlException(object(EntityEnclosingRequest), object(CurlHandle), array('msg' => '1', 'result' => '35', 'handle' => 'Resource id #2624')) in CurlMulti.php line 292
at CurlMulti->processResponse(object(EntityEnclosingRequest), object(CurlHandle), array('msg' => '1', 'result' => '35', 'handle' => 'Resource id #2624')) in CurlMulti.php line 257
at CurlMulti->processMessages() in CurlMulti.php line 240
at CurlMulti->executeHandles() in CurlMulti.php line 224
at CurlMulti->perform() in CurlMulti.php line 111
at CurlMulti->send() in CurlMultiProxy.php line 94
at CurlMultiProxy->send() in Client.php line 284
at Client->send(object(EntityEnclosingRequest)) in Client.php line 136
at Client->execute(object(OperationCommand)) in AbstractCommand.php line 153
at AbstractCommand->execute() in AbstractCommand.php line 189
at AbstractCommand->getResult() in KeenIOClient.php line 117
at KeenIOClient->addEvent('load_data', array(...)) in KeenIOClient.php line 87
tbarn commented 8 years ago

Hey @JakubMatejka! Thanks for opening this issue. We are gearing up for more work on the PHP SDK right now and will be looking more into this. We will keep this issue up to date.

J-who commented 8 years ago

Anything new on this? The connections issues today cause a lot of grief.

elof commented 8 years ago

84

J-who commented 8 years ago

Anything new on this? I've actually had to disable this tool after the last outage.

tbarn commented 8 years ago

@J-who Nothing new to report right now. In the next update of the SDK, we have this issue on the list of things to do. Sorry I don't have better news.

JakubMatejka commented 8 years ago

@tbarn Just out of curiosity, when should that next update happen? I reported this bug exactly four months ago and to be honest I don't understand the problem with fixing it. In my opinion bugs are to be fixed immediately and not to be waiting for some release date. Even when this one is so easy to fix and at the same time so annoying for the users (paying users to be exact).

It doesn't represent any problem for me anymore, I built my own retry mechanism around it rather than waiting for the fix but it is little bit "shameful" for your company I guess. If anyone needs to fix this, look to my solution here: https://github.com/keboola/gooddata-writer/blob/master/Service/KeenIO/KeenIOClient.php#L90 It is just simple wait & retry on any failure with fixed number of repetitions and 10-30 seconds wait (I think more complex solutions like exponential backoff aren't appropriate because nature of the outages is accidental and short lasting - and we are talking about "temporary" solution, right?)

tbarn commented 8 years ago

@JakubMatejka There's other SDKs being worked on right now, so I can't tell you an exact date. We are always open to pull requests and show our deepest appreciation for those who submit them. We very much consider our SDKs to be open source projects. We don't wait until release dates to push new versions of our SDKs. After a PR is submitted and reviewed, it gets released almost immediately.

In the latest update of this SDK, which was pushed to Packagist last week after the API reference docs were updated with all recent updates, we decided to suggest using existing Guzzle plugins like you suggested. You can see the commit here: https://github.com/keenlabs/KeenClient-PHP/commit/605af5713266da8f934f7a3aa1cf828bceb59609

The code would look something like this:

use KeenIO\Client\KeenIOClient;

$client = KeenIOClient::factory([
    'projectId' => $projectId,
    'writeKey'  => $writeKey,
    'readKey'   => $readKey
]);

// Use a static factory method to get a backoff plugin using the exponential backoff strategy
$backoffPlugin = BackoffPlugin::getExponentialBackoff();

// Add the backoff plugin to the client object
$client->addSubscriber($backoffPlugin);

We are constantly fixing bug fixes. Currently, since the plugin can be used and we added documentation to help with that, it didn't get fixed immediately like an urgent bug within the Keen IO API would. Would including the code I included in the README.md help resolve the issue for you?

@J-who are you okay with using the retry plugin for your use case? Hopefully the code I included is useful.

JakubMatejka commented 8 years ago

@tbarn That's great, I haven't realized that I can pass the backoff plugin directly to the keen.io client. It is perfectly sufficient to know it and notion in readme file would be fine. Well, I didn't create pull request because I wasn't sure if my suggestion is preferable for you, I was expecting rather some discussion about it. Anyway, thanks, I guess we can close this issue.

J-who commented 8 years ago

@tbarn Yeah looks like that'll work, I'll give it a shot. Thanks!