algolia / scout-extended

Scout Extended: The Full Power of Algolia in Laravel
https://www.algolia.com/doc/framework-integration/laravel/getting-started/introduction-to-scout-extended/
MIT License
395 stars 85 forks source link

cURL error 28: Resolving timed out after 2000 milliseconds #263

Closed sal1ner0 closed 3 years ago

sal1ner0 commented 3 years ago

Description

I'm having this error.. it seems something about network, but i tried from different servers, locations, etc.. and i cant figure out whats going on..

it happens always when i run scout:reimport directly on terminal or through laravel scheduler. The problem increases because most of the time it deletes the index and we run out of articles...

production.ERROR: cURL error 28: Resolving timed out after 2000 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://hjk5el3fft-dsn.algolia.net/1/indexes/catalog/settings?getVersion=2 {"exception":"[object] (GuzzleHttp\Exception\ConnectException(code: 0): cURL error 28: Resolving timed out after 2000 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://hjk5el3fft-dsn.algolia.net/1/indexes/catalog/settings?getVersion=2 at .../vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210)"} [

Steps To Reproduce

scout:reimport directly on terminal or through laravel scheduler.

DevinCodes commented 3 years ago

Hey, thanks for reaching out!

It seems like there's a connection timeout, could you please try to increase the connectTimeout threshold to see if that solves the issue? You can do this by replacing the default SearchClient with a custom one. In your AppServiceProvider, add something like the following code:

  public function register() {
    // ...
    $this->app->make(AlgoliaEngine::class)->setClient(SearchClient::createWithConfig(new SearchConfig([
        'appId' => getenv('ALGOLIA_APP_ID'),
        'apiKey' => getenv('ALGOLIA_API_KEY'),
        'connectTimeout' => 5, // Set connect timeout to 5 seconds instead of the default of 2
    ])));
    // ...
  }
sal1ner0 commented 3 years ago

Hi @DevinCodes !

I just tried, but still same error

cURL error 28: Resolving timed out after 2000 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://hjk5el3fft.algolia.net/1/indexes/manufactures/operation

It seems that this change does not take well..

DevinCodes commented 3 years ago

Can you please run the following command (Replace ApplicationID with your app ID) on the server where this error occurs, and send me the output? Thanks in advance!

curl -sL https://algolia.com/downloads/diag.sh > ./diag.sh && sudo ./diag.sh ApplicationID
sal1ner0 commented 3 years ago

Sure, here you have

Adding test for APPID: HJK5EL3FFT Ready to start! The tests will run for few minutes! System-Info: OK DNS-Settings: OK Dig: OK Dig-v6: OK Dig-v4: OK Dig-Trace: OK Port-80: OK Port-443: OK Geo: OK Hosts-net: OK Hosts-com: OK Dig-Google - latency-dsn.algolia.net: OK Dig-CF - latency-dsn.algolia.net: OK Ping - latency-dsn.algolia.net: Failure Failing this test does not indicate any specific issue Trace - latency-dsn.algolia.net: Not Available Trace-ICMP - latency-dsn.algolia.net: Not Available Connect - latency-dsn.algolia.net: Failure Failing this test does not indicate any specific issue MTR - latency-dsn.algolia.net: OK Dig-Google - latency-1.algolianet.com: OK Dig-CF - latency-1.algolianet.com: OK Ping - latency-1.algolianet.com: OK Trace - latency-1.algolianet.com: Not Available Trace-ICMP - latency-1.algolianet.com: Not Available Connect - latency-1.algolianet.com: OK MTR - latency-1.algolianet.com: OK Dig-Google - latency-2.algolianet.com: OK Dig-CF - latency-2.algolianet.com: OK Ping - latency-2.algolianet.com: OK Trace - latency-2.algolianet.com: Not Available Trace-ICMP - latency-2.algolianet.com: Not Available Connect - latency-2.algolianet.com: OK MTR - latency-2.algolianet.com: OK Dig-Google - latency-3.algolianet.com: OK Dig-CF - latency-3.algolianet.com: OK Ping - latency-3.algolianet.com: OK Trace - latency-3.algolianet.com: Not Available Trace-ICMP - latency-3.algolianet.com: Not Available Connect - latency-3.algolianet.com: OK MTR - latency-3.algolianet.com: OK Dig-Google - HJK5EL3FFT-dsn.algolia.net: OK Dig-CF - HJK5EL3FFT-dsn.algolia.net: OK Ping - HJK5EL3FFT-dsn.algolia.net: Failure Failing this test does not indicate any specific issue Trace - HJK5EL3FFT-dsn.algolia.net: Not Available Trace-ICMP - HJK5EL3FFT-dsn.algolia.net: Not Available Connect - HJK5EL3FFT-dsn.algolia.net: Failure Failing this test does not indicate any specific issue MTR - HJK5EL3FFT-dsn.algolia.net: OK Dig-Google - HJK5EL3FFT-1.algolianet.com: OK Dig-CF - HJK5EL3FFT-1.algolianet.com: OK Ping - HJK5EL3FFT-1.algolianet.com: OK Trace - HJK5EL3FFT-1.algolianet.com: Not Available Trace-ICMP - HJK5EL3FFT-1.algolianet.com: Not Available Connect - HJK5EL3FFT-1.algolianet.com: OK MTR - HJK5EL3FFT-1.algolianet.com: OK Dig-Google - HJK5EL3FFT-2.algolianet.com: OK Dig-CF - HJK5EL3FFT-2.algolianet.com: OK Ping - HJK5EL3FFT-2.algolianet.com: OK Trace - HJK5EL3FFT-2.algolianet.com: Not Available Trace-ICMP - HJK5EL3FFT-2.algolianet.com: Not Available Connect - HJK5EL3FFT-2.algolianet.com: OK MTR - HJK5EL3FFT-2.algolianet.com: OK Dig-Google - HJK5EL3FFT-3.algolianet.com: OK Dig-CF - HJK5EL3FFT-3.algolianet.com: OK Ping - HJK5EL3FFT-3.algolianet.com: OK Trace - HJK5EL3FFT-3.algolianet.com: Not Available Trace-ICMP - HJK5EL3FFT-3.algolianet.com: Not Available Connect - HJK5EL3FFT-3.algolianet.com: OK MTR - HJK5EL3FFT-3.algolianet.com: OK

DevinCodes commented 3 years ago

Thanks! I don't see anything weird in the output of the script, so let's try out some other possible fixes.

Hi @DevinCodes !

I just tried, but still same error

cURL error 28: Resolving timed out after 2000 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://hjk5el3fft.algolia.net/1/indexes/manufactures/operation

It seems that this change does not take well..

Given that the change does not get taken into account, you might have to customize the HTTP client that the API client uses, and set some cURL default in there. It would look something like the following code:

use Algolia\AlgoliaSearch\Algolia;
use GuzzleHttp\Client as GuzzleClient;

$httpClient = new Algolia\AlgoliaSearch\Http\Guzzle6HttpClient(
  new GuzzleClient([
    'connect_timeout' => 5,
  ])
);

Algolia::setHttpClient($httpClient);

Can you let me know if this yields any results? Thank you in advance!

sal1ner0 commented 3 years ago

ok i see..but how can i override reimport command with this settings?

DevinCodes commented 3 years ago

If you add this code in your register method of your AppServiceProvider, the underlying Algolia API client should use this new GuzzleClient as its HTTP client 🙂

sal1ner0 commented 3 years ago

It seems again that this change does not take well.. Still same error ;(

kossa commented 3 years ago

Facing the same error here

image

kossa commented 3 years ago

I fixed the issue by change composer.json, I used "algolia/scout-extended": "1.10.*" then composer update

image

sal1ner0 commented 3 years ago

Not working for me.. did u run manually or through scheduler?

kossa commented 3 years ago

Manually, bcz I had a problem with scout:status and scout:reimport

sal1ner0 commented 3 years ago

You're lucky .. I get the error even when executing it manually. if I manually execute the error it is only appear sometimes, which is even weirder. Let's wait for @DevinCodes

kossa commented 3 years ago

I remember another thing, I removed all indexes on Algolia, may be this is the cause 🤔

DevinCodes commented 3 years ago

Hey @sal1ner0 ,

sorry for the inconvenience, but I realize now that the snippet I provided in my comments earlier are in fact incorrect: they don't update your settings as expected. The following snippet should correctly update the timeouts. You might have to play around with the values to see what works best for your use case.

// AppServiceProvider.php

use Algolia\AlgoliaSearch\Config\SearchConfig;
use Algolia\AlgoliaSearch\SearchClient;

public function register() {
        $config = SearchConfig::create(config('scout.algolia.id'), config('scout.algolia.secret'));
        $config->setConnectTimeout(5); // You can set these values higher if needed.
        $config->setReadTimeout(5); // You can set these values higher if needed.
        $config->setWriteTimeout(5); // You can set these values higher if needed.

        $this->app->bind(SearchClient::class, function () use ($config) {
            return SearchClient::createWithConfig($config);
        });
}

Please let me know if this indeed solves your issue. If not, we can dig deeper into why this is happening.

Thanks in advance, and sorry for the back-and-forth 😄

sal1ner0 commented 3 years ago

Now sounds better ;).. It's works !! I only had to make a small change to your code: $config = SearchConfig::create(config('scout.algolia.id'), config('scout.algolia.secret')); Thanks @DevinCodes

DevinCodes commented 3 years ago

Awesome, thanks for letting me know! I've updated the snippet in my answer so if anyone encounters this later on, they'll have the correct snippet.

Cheers!

kossa commented 3 years ago

For my case I changed it to 10000(10 sec) I have the same issue :

image

DevinCodes commented 3 years ago

@kossa can you run the following command on the machine with this error? This may point towards network (configuration) errors. Just replace ApplicationID with your app id.

curl -sL https://algolia.com/downloads/diag.sh > ./diag.sh && sudo ./diag.sh ApplicationID
kossa commented 3 years ago

I got : sudo: ./diag.sh: command not found

DevinCodes commented 3 years ago

It seems like your machine can't download the command in that case. Is it able to connect to other sites (e.g. with the ping command)?

kossa commented 3 years ago

Sorry my mistake, I added chmod +x

Ready to start! The tests will run for few minutes! System-Info: OK DNS-Settings: OK Dig: OK Dig-v6: OK Dig-v4: OK Dig-Trace: OK Port-80: OK Port-443: OK Geo: OK Hosts-net: OK Hosts-com: OK Dig-Google - latency-dsn.algolia.net: OK Dig-CF - latency-dsn.algolia.net: OK Ping - latency-dsn.algolia.net: OK Trace - latency-dsn.algolia.net: Not Available Trace-ICMP - latency-dsn.algolia.net: Not Available Connect - latency-dsn.algolia.net: OK MTR - latency-dsn.algolia.net: OK Dig-Google - latency-1.algolianet.com: OK Dig-CF - latency-1.algolianet.com: OK Ping - latency-1.algolianet.com: OK Trace - latency-1.algolianet.com: Not Available Trace-ICMP - latency-1.algolianet.com: Not Available Connect - latency-1.algolianet.com: OK MTR - latency-1.algolianet.com: OK Dig-Google - latency-2.algolianet.com: OK Dig-CF - latency-2.algolianet.com: OK Ping - latency-2.algolianet.com: OK Trace - latency-2.algolianet.com: Not Available Trace-ICMP - latency-2.algolianet.com: Not Available Connect - latency-2.algolianet.com: OK MTR - latency-2.algolianet.com: OK Dig-Google - latency-3.algolianet.com: OK Dig-CF - latency-3.algolianet.com: OK Ping - latency-3.algolianet.com: OK Trace - latency-3.algolianet.com: Not Available Trace-ICMP - latency-3.algolianet.com: Not Available Connect - latency-3.algolianet.com: OK MTR - latency-3.algolianet.com: OK Dig-Google - KQT8KEMCEG-dsn.algolia.net: OK Dig-CF - KQT8KEMCEG-dsn.algolia.net: OK Ping - KQT8KEMCEG-dsn.algolia.net: OK Trace - KQT8KEMCEG-dsn.algolia.net: Not Available Trace-ICMP - KQT8KEMCEG-dsn.algolia.net: Not Available Connect - KQT8KEMCEG-dsn.algolia.net: OK MTR - KQT8KEMCEG-dsn.algolia.net: OK Dig-Google - KQT8KEMCEG-1.algolianet.com: OK Dig-CF - KQT8KEMCEG-1.algolianet.com: OK Ping - KQT8KEMCEG-1.algolianet.com: OK Trace - KQT8KEMCEG-1.algolianet.com: Not Available Trace-ICMP - KQT8KEMCEG-1.algolianet.com: Not Available Connect - KQT8KEMCEG-1.algolianet.com: OK MTR - KQT8KEMCEG-1.algolianet.com: OK Dig-Google - KQT8KEMCEG-2.algolianet.com: OK Dig-CF - KQT8KEMCEG-2.algolianet.com: OK Ping - KQT8KEMCEG-2.algolianet.com: OK Trace - KQT8KEMCEG-2.algolianet.com: Not Available Trace-ICMP - KQT8KEMCEG-2.algolianet.com: Not Available Connect - KQT8KEMCEG-2.algolianet.com: OK MTR - KQT8KEMCEG-2.algolianet.com: OK Dig-Google - KQT8KEMCEG-3.algolianet.com: OK Dig-CF - KQT8KEMCEG-3.algolianet.com: OK Ping - KQT8KEMCEG-3.algolianet.com: OK Trace - KQT8KEMCEG-3.algolianet.com: Not Available Trace-ICMP - KQT8KEMCEG-3.algolianet.com: Not Available Connect - KQT8KEMCEG-3.algolianet.com: OK MTR - KQT8KEMCEG-3.algolianet.com: OK

=================== End of diagnostics, please send this url: http://ix.io/2NuC to Algolia support, either by replying to the person that asked you to run the script or by sending a new email including your Application ID and why you had to run the script

DevinCodes commented 3 years ago

Hmm that's odd. Could you try with a value even higher than 10 seconds, let's say 30 seconds? If the problem still persists, feel free to send a message to Algolia support, so we can help dig a bit deeper.

kossa commented 3 years ago

I guess 10sec is a lot, if use need to wait 10sec to get the page ;)

koichirose commented 3 years ago

I'm having the same issue, tried with different timeouts (even 10 seconds). It started happening when I switched servers and maybe upgraded to PHP 8, but I'm not 100% sure about it being PHP 8's fault (I don't remember which version I had on the old VPS which is now unavailable).

Calling algolia via command-line curl is always ok and responses are pretty fast. Via PHP it sometimes works, it's unpredictable. Everything is at the latest version (scout-extended v1.14.0, Laravel v8.33.1, Guzzle v7.2.0).

Here's the output of algolia's diag:

Adding test for APPID: XJ8YNFLRU4
Ready to start!
The tests will run for few minutes!
System-Info: OK
DNS-Settings: OK
Dig: OK
Dig-v6: OK
Dig-v4: OK
Dig-Trace: OK
Port-80: OK
Port-443: OK
Geo: OK
Hosts-net: OK
Hosts-com: OK
Dig-Google - latency-dsn.algolia.net: OK
Dig-CF - latency-dsn.algolia.net: OK
Ping - latency-dsn.algolia.net: OK
Trace - latency-dsn.algolia.net: Not Available
Trace-ICMP - latency-dsn.algolia.net: Not Available
Connect - latency-dsn.algolia.net: OK
MTR - latency-dsn.algolia.net: OK
Dig-Google - latency-1.algolianet.com: OK
Dig-CF - latency-1.algolianet.com: OK
Ping - latency-1.algolianet.com: OK
Trace - latency-1.algolianet.com: Not Available
Trace-ICMP - latency-1.algolianet.com: Not Available
Connect - latency-1.algolianet.com: OK
MTR - latency-1.algolianet.com: OK
Dig-Google - latency-2.algolianet.com: OK
Dig-CF - latency-2.algolianet.com: OK
Ping - latency-2.algolianet.com: OK
Trace - latency-2.algolianet.com: Not Available
Trace-ICMP - latency-2.algolianet.com: Not Available
Connect - latency-2.algolianet.com: OK
MTR - latency-2.algolianet.com: OK
Dig-Google - latency-3.algolianet.com: OK
Dig-CF - latency-3.algolianet.com: OK
Ping - latency-3.algolianet.com: OK
Trace - latency-3.algolianet.com: Not Available
Trace-ICMP - latency-3.algolianet.com: Not Available
Connect - latency-3.algolianet.com: OK
MTR - latency-3.algolianet.com: OK
Dig-Google - XJ8YNFLRU4-dsn.algolia.net: OK
Dig-CF - XJ8YNFLRU4-dsn.algolia.net: OK
Ping - XJ8YNFLRU4-dsn.algolia.net: Failure
Failing this test does not indicate any specific issue
Trace - XJ8YNFLRU4-dsn.algolia.net: Not Available
Trace-ICMP - XJ8YNFLRU4-dsn.algolia.net: Not Available
Connect - XJ8YNFLRU4-dsn.algolia.net: Failure
Failing this test does not indicate any specific issue
MTR - XJ8YNFLRU4-dsn.algolia.net: OK
Dig-Google - XJ8YNFLRU4-1.algolianet.com: OK
Dig-CF - XJ8YNFLRU4-1.algolianet.com: OK
Ping - XJ8YNFLRU4-1.algolianet.com: OK
Trace - XJ8YNFLRU4-1.algolianet.com: Not Available
Trace-ICMP - XJ8YNFLRU4-1.algolianet.com: Not Available
Connect - XJ8YNFLRU4-1.algolianet.com: OK
MTR - XJ8YNFLRU4-1.algolianet.com: OK
Dig-Google - XJ8YNFLRU4-2.algolianet.com: OK
Dig-CF - XJ8YNFLRU4-2.algolianet.com: OK
Ping - XJ8YNFLRU4-2.algolianet.com: OK
Trace - XJ8YNFLRU4-2.algolianet.com: Not Available
Trace-ICMP - XJ8YNFLRU4-2.algolianet.com: Not Available
Connect - XJ8YNFLRU4-2.algolianet.com: Failure
Failing this test does not indicate any specific issue
MTR - XJ8YNFLRU4-2.algolianet.com: OK
Dig-Google - XJ8YNFLRU4-3.algolianet.com: OK
Dig-CF - XJ8YNFLRU4-3.algolianet.com: OK
Ping - XJ8YNFLRU4-3.algolianet.com: OK
Trace - XJ8YNFLRU4-3.algolianet.com: Not Available
Trace-ICMP - XJ8YNFLRU4-3.algolianet.com: Not Available
Connect - XJ8YNFLRU4-3.algolianet.com: OK
MTR - XJ8YNFLRU4-3.algolianet.com: OK

===================
End of diagnostics, please send this url: http://ix.io/2TaL to Algolia support, either by replying to the person that asked you to run the script or by sending a new email including your Application ID and why you had to run the script
koichirose commented 3 years ago

I don't want to be too optimistic, but in my case it seems that the new VPS has trouble with the default DNS. I switched to Cloudflare's DNS and everything seems to be fine now. Not sure why I was noticing the issue only with PHP and not if I called Algolia with curl.

DevinCodes commented 3 years ago

That's odd indeed, it might have to do with the PHP configuration in that case. Happy to hear it's resolved for you 😄