Skip to content

fix(dns): fix DNS cache completely invalid due to incorrect OPT RR filter order#2634

Merged
wwqgtxx merged 1 commit into
MetaCubeX:Alphafrom
woaihsw:fix-dns-cache
Mar 22, 2026
Merged

fix(dns): fix DNS cache completely invalid due to incorrect OPT RR filter order#2634
wwqgtxx merged 1 commit into
MetaCubeX:Alphafrom
woaihsw:fix-dns-cache

Conversation

@woaihsw

@woaihsw woaihsw commented Mar 22, 2026

Copy link
Copy Markdown

In commit c9bc2d3, the filtering of OPT RRs was moved inside the putMsgToCache function. However, the filtering is performed after the minimalTTL calculation.

Since the Header().Ttl field of an OPT RR (EDNS0) is used to encode extended RCODE, version, and DO flags (almost always resulting in 0), minimalTTL(lo.Concat(msg.Answer, msg.Ns, msg.Extra)) will invariably return 0. Consequently, putMsgToCache hits the if ttl == 0 { return } condition and skips caching for almost all normal DNS responses.

This commit fixes the issue by moving the OPT RR filtering to happen before calculating minimalTTL, restoring the expected DNS caching behavior.

…lter order

In commit c9bc2d3, the filtering of OPT RRs was moved inside the putMsgToCache function. However, the filtering is performed **after** the minimalTTL calculation.

Since the Header().Ttl field of an OPT RR (EDNS0) is used to encode extended RCODE, version, and DO flags (almost always resulting in 0), minimalTTL(lo.Concat(msg.Answer, msg.Ns, msg.Extra)) will invariably return 0. Consequently, putMsgToCache hits the if ttl == 0 { return } condition and skips caching for almost all normal DNS responses.

This commit fixes the issue by moving the OPT RR filtering to happen **before** calculating minimalTTL, restoring the expected DNS caching behavior.
@woaihsw woaihsw changed the title fix(dns): fix DNS cache completely invalid due to incorrect OPT RR fi… fix(dns): fix DNS cache completely invalid due to incorrect OPT RR filter order Mar 22, 2026
@wwqgtxx wwqgtxx merged commit d0f3312 into MetaCubeX:Alpha Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants