php / php/php-src

Weird behaviour for DNS resolution

Open
#14,245 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Category: DNS Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

I have look on the internet and see very little talk about this so it's possible that my php is wrongly configure but I have failed to find a directive related to this.

The following code:

Not sure where the code is located, my C understanding is pretty weak and I'm an ops guy.
I think it's around here : https://github.com/php/php-src/blob/master/ext/standard/dns.c

What I see :

When a php process does a dns query for both A and AAAA type, if A is valid but AAAA is empty, both records are not stored in cache and therefor the next request will trigger a dns query for both type again.
It seems like the empty AAAA response triggers an invalidation in the cache for both A and AAAA record. This behaviour floods the network needlessly.
I have notice this behaviour both on VMs or on containers, and from a wide range of php versions (5.6 to 8.3) or OS versions (Debian 9/10/11/12, Ubuntu 16/18/20/22 or Alpine 3.18/3.19).
I can provide this graph to illustrate better what I'm saying (Yellow and Green line are AAAA and A type) :
Screenshot 2024-05-15 at 14-47-35 CoreDNS - Kubernetes - Dashboards - Grafana

What I would expect :

In my opinion, once a A record have been successfully retrieved, it should be stored in cache and the AAAA should not invalidate it. And maybe once the A record expires it should try again both resolution (A and AAAA).

I have tested successfully to disable ipv6 in kernel for VMs and it drastically reduces the number of DNS query sent by applications (see graph below) and looks like the A response is stored in cache. This is a possible solution for VMs but complicated one in a Kubernetes environment.

Screenshot 2024-05-15 at 14-47-27 Unbound - System - Dashboards - Grafana

PHP Version

8.3

Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ext/standard/dns.c and reproduce the PHP 8.3 behavior with a hostname that has an A record but no AAAA record. Trace how the A and AAAA responses are cached or invalidated, then add or update focused coverage so a valid A result remains cached when the AAAA response is empty.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.