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

getting could not load the system's DNS configuration, using synchronous, blocking fallback error #101

Closed
raghuveer opened this issue Feb 2, 2021 · 9 comments

Comments

@raghuveer
Copy link

I am getting the following error when error reporting is turned on, irrespective of whether the db query is insert/update/select/delete, even though the expected operation is happening,

Warning: Could not load the system's DNS configuration, using synchronous, blocking fallback in /home/chat2/webapps/app-chat2/public_html/easeampmysqlredis/vendor/amphp/dns/lib/Rfc1035StubResolver.php on line 252

The php code is being run on ubuntu linux server and with php 7.4. Do we need to explicitly define dns resolver ip addresses (either google or opendns etc...), to fix this error? if yes, I would request you to please suggest with a code sample.

thank you

@kelunik kelunik transferred this issue from amphp/mysql Feb 2, 2021
@kelunik
Copy link
Member

kelunik commented Feb 2, 2021

@raghuveer I've transferred your issue to the correct repository. The systems configuration is usually automatically detected and used. The warning appears if loading the configuration fails, but TBH doesn't currently indicate the reason for that. The fallback is using the native resolver, but it can't resolve DNS names non-blocking in that state, so it issues a warning.

Could you have a look at the exception caught and provide that information here?

A new release improving the warning seems appropriate.

@kelunik
Copy link
Member

kelunik commented Feb 2, 2021

Please try with dev-master, I've pushed 659bad6.

@raghuveer
Copy link
Author

raghuveer commented Feb 3, 2021

Thanks @kelunik, tried running amphp/dns package from dev-master as you suggested,

my server setup:
Ubuntu 18.04
PHP v7.4.14 with PHP-FPM and Nginx before Apache web server

ran sample code from https://github.com/amphp/dns,
`require 'vendor/autoload.php';

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use Amp\Dns;
use Amp\Loop;

Loop::run(function () {
$githubIpv4 = yield Dns\resolve("github.com", Dns\Record::A);
pretty_print_records("github.com", $githubIpv4);

$googleIpv4 = Amp\Dns\resolve("google.com", Dns\Record::A);
$googleIpv6 = Amp\Dns\resolve("google.com", Dns\Record::AAAA);

$firstGoogleResult = yield Amp\Promise\first([$googleIpv4, $googleIpv6]);
pretty_print_records("google.com", $firstGoogleResult);

$combinedGoogleResult = yield Amp\Dns\resolve("google.com");
pretty_print_records("google.com", $combinedGoogleResult);

$googleMx = yield Amp\Dns\query("google.com", Amp\Dns\Record::MX);
pretty_print_records("google.com", $googleMx);

});
`
got the following error,

Warning: Could not load the system's DNS configuration; falling back to synchronous, blocking resolver; Amp\Dns\ConfigException: Could not read configuration file '/etc/resolv.conf' (2) file_get_contents(): open_basedir restriction in effect. File(/etc/resolv.conf) is not within the allowed path(s): (/home/chat2/webapps/app-chat2:/var/lib/php/session:/tmp) in /home/chat2/webapps/app-chat2/public_html/amphp-dns/vendor/amphp/dns/lib/Rfc1035StubResolver.php on line 260

Fatal error: Uncaught Error: Call to undefined function pretty_print_records() in /home/chat2/webapps/app-chat2/public_html/amphp-dns/index.php:13 Stack trace: #0 [internal function]: {closure}() #1 /home/chat2/webapps/app-chat2/public_html/amphp-dns/vendor/amphp/amp/lib/Coroutine.php(118): Generator->send() #2 /home/chat2/webapps/app-chat2/public_html/amphp-dns/vendor/amphp/amp/lib/Success.php(41): Amp\Coroutine->Amp{closure}() #3 /home/chat2/webapps/app-chat2/public_html/amphp-dns/vendor/amphp/amp/lib/Internal/Placeholder.php(40): Amp\Success->onResolve() #4 /home/chat2/webapps/app-chat2/public_html/amphp-dns/vendor/amphp/amp/lib/Coroutine.php(151): Amp\Coroutine->onResolve() #5 /home/chat2/webapps/app-chat2/public_html/amphp-dns/vendor/amphp/amp/lib/Loop/Driver.php(126): Amp\Coroutine->__construct() #6 /home/chat2/webapps/app-chat2/public_html/amphp-dns/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick() #7 /home/chat2/webapps/app-chat2/public_html/amphp-dns/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Dr in /home/chat2/webapps/app-chat2/public_html/amphp-dns/index.php on line 13

is there any way we can access /etc/resolv.conf file without disabling open_basedir restrictions? or alternatively, can we define native resolver, as you shared earlier locally as manual config? that other amphp\socket library uses, that inturn is used by amphp/mysql library, that I am using in my application?

please share your inputs, thank you

@raghuveer
Copy link
Author

raghuveer commented Feb 5, 2021

@kelunik

is there any alternative solution for amphp/dns to access /etc/resolv.conf without disabling open_basedir restrictions?

I did try the example at https://github.com/amphp/dns/blob/master/examples/custom-config.php, by providing a numeric index array of hostnames,

$argv = ["microsoft.com","google.com","yahoo.com"];

With google offered recursive dns servers being used in the custom config, I see available list of IPv4 and IPv6 addresses in the result, for whichever hostname is given in the input, I would like to know about how this custom config be consumed by all dependencies of amphp/mysql library like amphp/socket (that uses amphp/dns library)? or is there a way for us to define this recursive DNS Servers info as custom config of Amphp/dns library, when using amphp/mysql library in our application?

your inputs and support will be really helpful,

thank you

@kelunik
Copy link
Member

kelunik commented Feb 5, 2021

@raghuveer You've found the correct example. Dns\resolver(new Dns\Rfc1035StubResolver(null, $customConfigLoader)); sets the given configuration globally, so it's automatically used by all packages like amphp/socket and amphp/mysql.

@raghuveer
Copy link
Author

Thanks a lot @kelunik it worked, I will try including this in my application :)

@raghuveer
Copy link
Author

What are the suggested number of attempts? the number in the sample code is 3.

I did try adding more recursive DNS Servers (like 2 IPv4 Addresses of opendns.com), to the existing Google Recursive DNS Server IPv4 Address (8.8.8.8) and some IPv6 Address

`$customConfigLoader = new class implements Dns\ConfigLoader {
public function loadConfig(): Promise
{
return Amp\call(function () {
$hosts = yield (new Dns\HostLoader)->loadHosts();

        return new Dns\Config([
            "208.67.222.222:53", "208.67.220.220:53","8.8.8.8:53","[2001:4860:4860::8888]:53"
        ], $hosts, $timeout = 5000, $attempts = 3);
    });
}

};

Dns\resolver(new Dns\Rfc1035StubResolver(null, $customConfigLoader));
`

is this ok? please share your inputs,

thank you

@raghuveer raghuveer reopened this Feb 5, 2021
@kelunik
Copy link
Member

kelunik commented Feb 5, 2021

That depends on your needs on speed and reliability. I think 2 or 3 are the default. The total timeout will be attempt * timeout I think.

@raghuveer
Copy link
Author

I am using the defaults as per your example, thank you @kelunik

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

No branches or pull requests

2 participants