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

fix: dns interceptor ip ttl #3770

Merged
merged 3 commits into from
Oct 27, 2024
Merged

Conversation

luddd3
Copy link
Contributor

@luddd3 luddd3 commented Oct 25, 2024

This relates to...

How long time to cache the dns records from the dns interceptor.

Rationale

For how long time the dns records from the dns interceptor should live.

Changes

Set timestamp once on each resolved record and compare the ttl to that timestamp. If the record is too old, remove it.

Features

Bug Fixes

N/A

Breaking Changes and Deprecations

Status

This fixes so that the record lives at most ttl time since lookup by not
refreshing the timeout when picked.
@luddd3 luddd3 changed the title fix: dns interceptor ip may never time out fix: dns interceptor ip ttl Oct 25, 2024
lib/interceptor/dns.js Outdated Show resolved Hide resolved
const records = { records: { 4: null, 6: null } }
for (const record of addresses) {
record.timestamp = timestamp
record.ttl = opts.maxTTL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the record already contains a ttl let's preserve it, otherwise default to maxTTL.

On top, let's use the min from both values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added it.

How do you feel about expecting the record result to be in ms? dns.lookup doesn't usually provide ttl. dns.resolve does, but it's ttl, and other time properties, are in seconds.
https://nodejs.org/api/dns.html#dnsresolveanyhostname-callback

Take the minimum value between the record TTL and the maxTTL from
options. The record TTL value is expected to be in ms even though the
`dns.resolve` methods provide it in seconds. The reasons are that:

* it avoids extra manipulation in the `setRecords` method
* `dns.lookup` does not provide ttl
* custom provided lookup method's using `dns.resolve` must be
  manipulated anyway by adding a value for the family.
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@metcoder95 metcoder95 merged commit 2de0f34 into nodejs:main Oct 27, 2024
27 of 31 checks passed
@luddd3 luddd3 deleted the fix-dns-interceptor-ttl branch October 28, 2024 05:28
@github-actions github-actions bot mentioned this pull request Dec 3, 2024
This was referenced Dec 16, 2024
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.

3 participants