mailjet / mailjet-apiv3-php

[API v3] Mailjet PHP Wrapper
http://dev.mailjet.com
MIT License
262 stars 85 forks source link

cURL timeout #157

Closed tjerkhamer closed 3 years ago

tjerkhamer commented 5 years ago

A lot of times when we try to send an email through the wrapper, we experience a cURL timeout (2500 ms)

Today (and many times before) we send a request to the api with an almost empty html and text part and received an fatal error because of the timeout. The request came in on our server at 09:52:52, was the request to Mailjet started at 09:52:54 and received the timeout at 09:52:57.

A conversation with support @ mailjet didn't solve anything besides a work around to keep sending until the request is accepted by Mailjet, which isn't a very sustainable solution.

Can anybody please help us solve this problem, so we can start using Mailjet as our mailserver.

kmanchikov commented 5 years ago

Hi Tjerk,

If I'am not mistaken the "cURL timeout (2500 ms)" should implement that this should be a hard limit for how long time a request is allowed to take, and yours seems to be set to 2.5sec. So in this case the request took a bit longer to reach Mailjet thus this request timed out. You could use 0 to wait indefinitely or set the limit to be equals to 20 seconds, as far as I know this is the maximum limit that Mailjet would take to handle the request.

launtony commented 5 years ago

Hi guys, I have this problem since some days :/ I have increase the delay to 15sec but same problem :/ I suspect internet problem on my hosting provider OVH :/ But I don't know :( Any idea?

todorDim commented 5 years ago

Hello @launtony,

Does the issue still persist ?

Regards, T.

launtony commented 5 years ago

Hi :)

No problem since few weeks :)

Do you have made some changes?

Thanks,

iMagicKey commented 5 years ago

Hello! We still have this problem. A couple of days ago we increased the timeout from 5 to 15 seconds, but this did not help. cURL error 28: Operation timed out after 15001 milliseconds with 0 out of -1 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

For example errors was happend in (GMT+1): 01.03.2019 13:01:39 01.03.2019 13:01:24 01.03.2019 06:34:46 01.03.2019 06:34:10

Does anyone know how to solve this problem?

abambova commented 5 years ago

Hi @iMagicKey , We will test on our side the issue and come back to you with more details. Thanks!

launtony commented 5 years ago

Hi,

I had this error yesterday (3 times) :/

Thanks,

abambova commented 5 years ago

Hi @launtony and @iMagicKey , Could you please increase the timeout to 20s? Please let us know if it solves the issue you are facing. Thanks!

iMagicKey commented 5 years ago

Hi @abambova, we have errors again.

cURL error 28: Operation timed out after 20001 milliseconds with 0 out of -1 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Errors was happend in (GMT+1): 14.03.2019 14:00:09 15.03.2019 11:30:25 15.03.2019 11:31:20 15.03.2019 11:31:22 15.03.2019 11:31:46 16.03.2019 08:00:25 16.03.2019 08:00:45 16.03.2019 08:01:11 16.03.2019 08:01:15 18.03.2019 06:35:09

21.03.2019 16:03:39 21.03.2019 16:03:40 21.03.2019 16:03:41 21.03.2019 16:03:52 21.03.2019 16:03:59

nadar commented 5 years ago

We do have the timeout issues as well from time to time.

abambova commented 5 years ago

Could you please contact our support team for that https://app.mailjet.com/support/ticket ? they will help you with solving this issue. Thanks!

jkgroupe commented 5 years ago

Hi guys, I have this problem since some days :/ I have increase the delay to 15sec but same problem :/ I suspect internet problem on my hosting provider OVH :/ But I don't know :( Any idea?

I think this problem comes from OVH because I have the same one

launtony commented 5 years ago

@jkgroupe You think ? I haven't this error since few days now :) I have this error some times :/ I have developp a system on my app to retry just once if I have this error :/

cbou commented 5 years ago

We have the same problem too.

In our case the issue is related to CONNECT_TIMEOUT. I increase it to 5 but it didn't help. Sometimes it works but sometimes it does not.

At the moment the code is under development so it's not a real issue but this could prevent us to deploy Mailjet :(

I hope it will be fixed soon.

I tried different Internet connections...

Golden21000 commented 5 years ago

We have this problem too, again and again... Any solution ?

Mailjet support wants i install :

04/09/2019 - 10:37:50 --- GuzzleHttp\Exception\ConnectException: cURL error 28: Operation timed out after 15001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /home/vhosts/locavor/locavorinclude/mailjet-apiv3-php/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:185 04/09/2019 - 10:36:58 --- GuzzleHttp\Exception\ConnectException: cURL error 28: Operation timed out after 15001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /home/vhosts/locavor/locavorinclude/mailjet-apiv3-php/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:185 04/09/2019 - 10:01:50 --- GuzzleHttp\Exception\ConnectException: cURL error 28: Operation timed out after 15001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /home/vhosts/locavor/locavorinclude/mailjet-apiv3-php/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:185 25/08/2019 - 9:36:04 --- GuzzleHttp\Exception\ConnectException: cURL error 28: Operation timed out after 15001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /home/vhosts/locavor/locavorinclude/mailjet-apiv3-php/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:185 ...etc...

jkgroupe commented 5 years ago

@jkgroupe You think ? I haven't this error since few days now :) I have this error some times :/ I have developp a system on my app to retry just once if I have this error :/

In my case I have made a loop to retry to send the mail if I have a timeout and it works perfectly :)

cbou commented 4 years ago

I was able to reproduce it twice the previous days (with two different internet connections) so I guess it' still there.

My scenario was (all the steps in a loop 50 times):

Sometimes it pass and I receive 50 emails (most of the time) but sometimes I get the timeout error.

It would be interesting to know if other SDK has the problem.

Lucassifoni commented 4 years ago

Hello, We're experiencing the same random timeouts with multiple languages (PHP, Elixir) on multiple hosting providers (OVH, DigitalOcean). Increasing the timeout and / or re-queuing sends was the only solution for us.

peter279k commented 4 years ago

I think this is a temporary error.

I get this connection timeout error, and I retry doing e-mail sending after few seconds.

Then it's successful.

BigBenJr commented 4 years ago

I am implementing MailJet on my app, I experienced this cURL timeout several times since i am doing different local tests. The last one doing this:

$filters = ['ContactEmail' => 'xxx', 'ContactsList' => xxx, 'unsub' => false]; $response = $mj->get(\Mailjet\Resources::$Listrecipient, ['filters' => $filters]); $response->success() && var_dump($response->getData());

I got this:

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 28: Connection timed out after 2000 milliseconds

I refresh the request and then it's working... no timeout issue. But 10 minutes later I do the same request and I get an other cURL timeout again. I am afraid it may happen everytime... everywhere... to anyone using my app... ?

EDIT 1

I raise timeout to 3 secondes, I sent the same request and I got this:

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 28: Operation timed out after 3000 milliseconds with 0 out of 0 bytes received

I find that strange "0 out of 0 bytes recevied". I guess it means than even if I raise timeout to 20 secondes the problem will still be the same.

EDIT 2

I raise timeout to 20 secondes. I sent the same request several times and it's working, but sometimes I must wait more than 5 secondes... I even experienced a 10 seconds waiting, its quiet horrible.

EDIT 3

My slow connexion was the main reason of this huge latency, my system was on a update... -_-". As it may happens to every of our users I suggest that maybe this 2 seconds timeout should be raise by default ?

Lucassifoni commented 4 years ago

Hello @BigBenJr , Expect timeouts on a regular basis in production. We implemented incremental retries in our app in a separate process to avoid complications.

We try to send mail up to 6 times, retrying after 5, 15, 30, 60, 120, 240 seconds. After the sixth attempt, we log an exception and we get an e-mail (with another provider) alerting us. This already happened several times.

You can't prevent all failures but it's already something.

uavn commented 3 years ago

Closing. Workaround mentioned in the comments, actually it is standard solution for such third-party integrations, and it is not about SDK, it is about mailjet API service.

liamcharmer commented 3 years ago

Closing. Workaround mentioned in the comments, actually it is standard solution for such third-party integrations, and it is not about SDK, it is about mailjet API service.

So the "mentioned workaround" is to do what?

From

  $response = $mj->post(Resources::$Email, ['body' => $body]);

to

  $response = $mj->post(Resources::$Email, ['body' => $body,  'timeout' => 10000,  'connect_timeout' => 10000]);

We assume? And then retries?

AnnoyingTechnology commented 1 year ago
$client // (the Mailjet\Client)
    ->setTimeout(20)
    ->setConnectionTimeout(20);
uavn commented 1 year ago

Sorry for not being clear about workaround:

Connection timeout means that API host is unreachable, service can be down or just overloaded, your network can be unstable, etc., it doesn't really matter.

The best solution (workaround) is to implement some retry logic, so you can add your mail job to the background queue (can be mysql + cron or amqp, or which way you preferer), and then try to execute it with some delays, if first attempt failed, call it in a few minutes, and maybe in a few minutes again if it failed, most probably it'll work fine from another try.

Sending email jobs to the background processes is a good practice anyway.

AnnoyingTechnology commented 1 year ago

We do queue emails, but we are trying to weed out Mailjet API Errors that pollute logs files and alerting systems. Increasing the timeout to match the API's seems reasonable.

uavn commented 1 year ago

@AnnoyingTechnology You can wrap it in try catch if not yet, and yes, increasing timeout can help sometime