mailgun / mailgun-php

Mailgun's Official SDK for PHP
http://www.mailgun.com
MIT License
1.1k stars 314 forks source link

Mailgun's servers are currently unreachable. #843

Closed mikeytag closed 1 year ago

mikeytag commented 1 year ago

I'm currently on 2.8.1 which is an older release and I'm wondering if that's part of the problem, but I'm getting the following Exception message intermittently.

Mailgun's servers are currently unreachable.

Almost all of our API requests are successful, but I started seeing these exceptions starting yesterday. The Mailgun health status doesn't report any issues, so I'm guessing that the issue is on my end.

Do you think that running an older version of this library could be the culprit?

oleksandr-mykhailenko commented 1 year ago

Hello @mikeytag It could be, in theory Do you have an example of error message and what you do during getting this ?

mikeytag commented 1 year ago

Thanks @oleksandr-mykhailenko. It's happening intermittently when calling the send() method. The exact implementation looks like this:

$response = self::$_Mailgun->messages()->send($this->_domain, $mailgun_args);

The stack traces in Sentry.io are simply showing that it's an Exception with the message:

Mailgun's servers are currently unreachable.

That's all I have. Keep in mind that we are able to do thousands of emails just fine, but in the last 24 hours there's been 702 of these Exceptions where they never have happened before.

This smells to me like some type of DNS connection issue and the problem could entirely be on my end. However, we hit many external APIs (Google, Bing, Facebook, etc) millions of times a day and I'm not having any connection issues with any other one.

We currently are running v2.8.1 of the mailgun-php library on PHP 7.3 in Fargate on AWS.

mikeytag commented 1 year ago

I should also add that we only use Mailgun to send emails internally to us. In this case, the Exception is being thrown trying to send backup emails to some members of our company after a lead is generated.

I'm going to take a look at our Mailgun backend and see if I notice anything there. There's this SO post that could indicate I have an issue with the domain.

https://stackoverflow.com/questions/64860996/error-500-mailguns-servers-are-currently-unreachable

mikeytag commented 1 year ago

Ok, the domain that is throwing the Exceptions is reporting 100% delivered in Mailgun and no issues there 🤔

mikeytag commented 1 year ago

I'm digging through the mailgun-php code and it looks like it does an HTTP POST to /v3/%s/messages when sending. The URL it hits seems to be: api.mailgun.net

mikeytag commented 1 year ago

I found something interesting deep in the stack trace. There was some XML that was making it into the email body and I have a hunch that was throwing things off. I'm removing that to see if that fixes the issue.

mikeytag commented 1 year ago

Hmmmm, I'm still getting these network errors even with the XML removed that I thought could be causing the problem.

mikeytag commented 1 year ago

The exact exception is thrown from Mailgun\Exception\HttpServerException::networkError at line 26

    {
        return new self('Mailgun\'s servers are currently unreachable.', 0, $previous);
    }

which is called by Mailgun\Api\HttpApi::httpPostRaw at line 163

            $response = $this->httpClient->sendRequest(
                $this->requestBuilder->create('POST', $path, $requestHeaders, $body)
            );
        } catch (HttplugException\NetworkException $e) {
            throw HttpServerException::networkError($e);
        }
JasonTame commented 1 year ago

We have exactly the same issue - started happening intermittently a few months back and is now happening at least once a day.

mikeytag commented 1 year ago

Nice to know I'm not alone. I can't get it to stop happening. I'm going to reach out to Mailgun directly and see if I can get any clarity around root causes.

oleksandr-mykhailenko commented 1 year ago

@mikeytag @JasonTame Hello, do you have a message from exception ? Maybe it contains more information

oleksandr-mykhailenko commented 1 year ago

Close the issues due to inactivity