DNS Query failed at /usr/local/www/nextcloud/lib/private/Http/Client/DnsPinMiddleware.php

Nextcloud version (eg, 20.0.5): 22.2.0
Operating system and version (eg, Ubuntu 20.04): FreeBSD 12.2-RELEASE-p10 (in an iocage jail)
Apache or nginx version (eg, Apache 2.4.25): nginx 1.20.1_5
PHP version (eg, 7.4): 8.0.12

Hi,

My nextcloud.log file is filled with these DNS Query failed messages. Is this a bug or something I can correct via config?

Is this the first time you’ve seen this error? (Y/N): N

The output of your Nextcloud log in Admin > Logging:

{"reqId":"70cUAvIuOd1FX2SeMQUo","level":3,"time":"2021-10-30T08:55:29-04:00","remoteAddr":"192.168.1.163","user":"[Hidden]","app":"PHP","method":"GET","url":"/ocs/v2.php/apps/weather_status/api/v1/forecast","message":"dns_get_record(): DNS Query failed at /usr/local/www/nextcloud/lib/private/Http/Client/DnsPinMiddleware.php#83","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36","version":"22.2.0.2","exception":{"Exception":"Error","Message":"dns_get_record(): DNS Query failed at /usr/local/www/nextcloud/lib/private/Http/Client/DnsPinMiddleware.php#83","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::","args":[2,"dns_get_record(): DNS Query failed","/usr/local/www/nextcloud/lib/private/Http/Client/DnsPinMiddleware.php",83]},{"file":"/usr/local/www/nextcloud/lib/private/Http/Client/DnsPinMiddleware.php","line":83,"function":"dns_get_record","args":["api.met.no",16]},{"file":"/usr/local/www/nextcloud/lib/private/Http/Client/DnsPinMiddleware.php","line":128,"function":"dnsResolve","class":"OC\\Http\\Client\\DnsPinMiddleware","type":"->","args":["api.met.no",1]},{"file":"/usr/local/www/nextcloud/3rdparty/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php","line":35,"function":"OC\\Http\\Client\\{closure}","class":"OC\\Http\\Client\\DnsPinMiddleware","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/usr/local/www/nextcloud/3rdparty/guzzlehttp/guzzle/src/Middleware.php","line":31,"function":"__invoke","class":"GuzzleHttp\\PrepareBodyMiddleware","type":"->","args":["*** sensitive parameter replaced ***","*** sensitive parameter replaced ***"]},{"file":"/usr/local/www/nextcloud/3rdparty/guzzlehttp/guzzle/src/RedirectMiddleware.php","line":71,"function":"GuzzleHttp\\{closure}","class":"GuzzleHttp\\Middleware","type":"::","args":["*** sensitive parameters replaced ***"]},{"file":"/usr/local/www/nextcloud/3rdparty/guzzlehttp/guzzle/src/Middleware.php","line":63,"function":"__invoke","class":"GuzzleHttp\\RedirectMiddleware","type":"->","args":["*** sensitive parameter replaced ***","*** sensitive parameter replaced ***"]},{"file":"/usr/local/www/nextcloud/3rdparty/guzzlehttp/guzzle/src/HandlerStack.php","line":75,"function":"GuzzleHttp\\{closure}","class":"GuzzleHttp\\Middleware","type":"::","args":["*** sensitive parameters replaced ***"]},{"file":"/usr/local/www/nextcloud/3rdparty/guzzlehttp/guzzle/src/Client.php","line":331,"function":"__invoke","class":"GuzzleHttp\\HandlerStack","type":"->","args":["*** sensitive parameter replaced ***","*** sensitive parameter replaced ***"]},{"file":"/usr/local/www/nextcloud/3rdparty/guzzlehttp/guzzle/src/Client.php","line":168,"function":"transfer","class":"GuzzleHttp\\Client","type":"->","args":["*** sensitive parameter replaced ***","*** sensitive parameter replaced ***"]},{"file":"/usr/local/www/nextcloud/3rdparty/guzzlehttp/guzzle/src/Client.php","line":187,"function":"requestAsync","class":"GuzzleHttp\\Client","type":"->","args":["get",{"__class__":"GuzzleHttp\\Psr7\\Uri"},{"verify":"/usr/local/www/nextcloud/resources/config/ca-bundle.crt","timeout":30,"allow_redirects":{"on_redirect":{"__class__":"Closure"}},"nextcloud":{"allow_local_address":false},"synchronous":true,"0":"And 6 more entries, set log level to debug to see all entries"}]},{"file":"/usr/local/www/nextcloud/lib/private/Http/Client/Client.php","line":223,"function":"request","class":"GuzzleHttp\\Client","type":"->","args":["get","https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=42.27&lon=-71.23&altitude=64",{"verify":"/usr/local/www/nextcloud/resources/config/ca-bundle.crt","timeout":30,"allow_redirects":{"on_redirect":{"__class__":"Closure"}},"headers":{"User-Agent":"NextcloudWeatherStatus/1.2.0 nextcloud.com","Accept-Encoding":"gzip"},"nextcloud":{"allow_local_address":false},"0":"And 1 more entries, set log level to debug to see all entries"}]},{"file":"/usr/local/www/nextcloud/apps-pkg/weather_status/lib/Service/WeatherStatusService.php","line":415,"function":"get","class":"OC\\Http\\Client\\Client","type":"->","args":["https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=42.27&lon=-71.23&altitude=64",{"headers":{"User-Agent":"NextcloudWeatherStatus/1.2.0 nextcloud.com"}}]},{"file":"/usr/local/www/nextcloud/apps-pkg/weather_status/lib/Service/WeatherStatusService.php","line":380,"function":"requestJSON","class":"OCA\\WeatherStatus\\Service\\WeatherStatusService","type":"->","args":["https://api.met.no/weatherapi/locationforecast/2.0/compact",{"lat":"42.27","lon":"-71.23","altitude":64}]},{"file":"/usr/local/www/nextcloud/apps-pkg/weather_status/lib/Service/WeatherStatusService.php","line":358,"function":"forecastRequest","class":"OCA\\WeatherStatus\\Service\\WeatherStatusService","type":"->","args":[42.27082285,-71.2343990606968,64]},{"file":"/usr/local/www/nextcloud/apps-pkg/weather_status/lib/Controller/WeatherStatusController.php","line":118,"function":"getForecast","class":"OCA\\WeatherStatus\\Service\\WeatherStatusService","type":"->","args":[]},{"file":"/usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":217,"function":"getForecast","class":"OCA\\WeatherStatus\\Controller\\WeatherStatusController","type":"->","args":[]},{"file":"/usr/local/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":126,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\WeatherStatus\\Controller\\WeatherStatusController"},"getForecast"]},{"file":"/usr/local/www/nextcloud/lib/private/AppFramework/App.php","line":156,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\WeatherStatus\\Controller\\WeatherStatusController"},"getForecast"]},{"file":"/usr/local/www/nextcloud/lib/private/Route/Router.php","line":301,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\WeatherStatus\\Controller\\WeatherStatusController","getForecast",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"_route":"ocs.weather_status.WeatherStatus.getForecast"}]},{"file":"/usr/local/www/nextcloud/ocs/v1.php","line":62,"function":"match","class":"OC\\Route\\Router","type":"->","args":["/ocsapp/apps/weather_status/api/v1/forecast"]},{"file":"/usr/local/www/nextcloud/ocs/v2.php","line":23,"args":["/usr/local/www/nextcloud/ocs/v1.php"],"function":"require_once"}],"File":"/usr/local/www/nextcloud/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"}}

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/usr/local/www/nextcloud/apps',
      'url' => '/apps',
      'writable' => true,
    ),
    1 => 
    array (
      'path' => '/usr/local/www/nextcloud/apps-pkg',
      'url' => '/apps-pkg',
      'writable' => false,
    ),
  ),
  'logfile' => '/var/log/nextcloud/nextcloud.log',
  'log_type' => 'file',
  'loglevel' => 2,
  'logrotate_size' => 10 * 1024 * 1024,
  'logtimezone' => 'America/New_York',
  'default_phone_region' => 'US',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'passwordsalt' => '[hidden]',
  'secret' => '[hidden]',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '192.168.1.102',
    2 => '[hidden]',
  ),
  'trusted_proxies' => 
  array (
    0 => '192.168.1.1',
  ),
  'datadirectory' => '/usr/local/www/nextcloud/data',
  'trashbin_retention_obligation' => 'auto, 7',
  'dbtype' => 'mysql',
  'version' => '22.2.0.2',
  'dbname' => 'nextcloud',
  'dbhost' => '[hidden]',
  'dbport' => '3306',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '[hidden]',
  'installed' => true,
  'instanceid' => 'oc9iozdpogk2',
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
  ),
  'enable_previews' => true,
  'preview_max_x' => 1024,
  'preview_max_y' => 1024,
  'preview_max_filesize_image' => 50,
  'enabledPreviewProviders' => 
  array (
    0 => 'OC\\Preview\\PNG',
    1 => 'OC\\Preview\\JPEG',
    2 => 'OC\\Preview\\GIF',
    3 => 'OC\\Preview\\HEIC',
    4 => 'OC\\Preview\\BMP',
    5 => 'OC\\Preview\\XBitmap',
    6 => 'OC\\Preview\\MP3',
    7 => 'OC\\Preview\\TXT',
    8 => 'OC\\Preview\\MarkDown',
    9 => 'OC\\Preview\\PDF',
  ),
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'tls',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => '[hidden]',
  'mail_domain' => '[hidden]',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => '[hidden]',
  'mail_smtpname' => '[hidden]',
  'mail_smtppassword' => '[hidden]',
  'mail_smtpport' => '587',
  'mail_smtpdebug' => false,
  'twofactor_enforced' => 'true',
  'twofactor_enforced_groups' => 
  array (
    0 => 'admin',
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
  'theme' => '',
  'maintenance' => false,
  'updater.release.channel' => 'stable',
  'overwrite.cli.url' => '[hidden]',
  'jpeg_quality' => '60',
  'app_install_overwrite' => 
  array (
    0 => 'previewgenerator',
    1 => 'video_converter',
    2 => 'extract',
  ),
);

Hello
I have a very similar if not the same issue on FreeBsd 12 with php 7.4 also. This is similar to the issue Bug in DnsPinMiddleware.php, "DNS Query failed" · Issue #28105 · nextcloud/server · GitHub and Bug in DnsPinMiddleware.php, unable to resolve hostname · Issue #27870 · nextcloud/server · GitHub . I followed the troubleshooting steps mentionned and the error is with retrieving the DNS_CNAME:

$ php -r “var_dump(dns_get_record(‘apps.nextcloud.com’, DNS_A | DNS_AAAA | DNS_CNAME));”
PHP Warning: dns_get_record(): DNS Query failed in Command line code on line 1
bool(false)

I understand that Nextcloud is not supported on FreeBsd, but let us know if there is a way to fix this :wink:

1 Like

That problem is not related to FreeBSD. The Problem is, that apps.bextcloud.com does not have a record for CNAME, see DNS Lookup.

image

Thats why the PHP warning occurs.
The question is, how to handle missing records?

Exactly.
Every time the Nextcloud server looks up a CNAME record and gets a reply that there’s no such record, it logs it, which I find annoying and hot helpful. Even more so because most of these CNAME lookups are for nextcloud.com subdomains (www, apps, updates, pushfeed and push-notifications).

Odd because as far as I understand about DNS, you don’t need a CNAME (alias) if you already have an A record for that same host, which is would be what is returned from a DNS query. Seems like a bug?