René's URL Explorer Experiment


Title: HostsFileParser: lookups during a hosts file reload miss existing entries · Issue #429 · dnsjava/dnsjava · GitHub

Open Graph Title: HostsFileParser: lookups during a hosts file reload miss existing entries · Issue #429 · dnsjava/dnsjava

X Title: HostsFileParser: lookups during a hosts file reload miss existing entries · Issue #429 · dnsjava/dnsjava

Description: Summary HostsFileParser reloads a changed hosts file by clearing its maps in place and then refilling them. Lookups read those maps without the lock, so a lookup that runs between the clear and the refill gets Optional.empty() for a name...

Open Graph Description: Summary HostsFileParser reloads a changed hosts file by clearing its maps in place and then refilling them. Lookups read those maps without the lock, so a lookup that runs between the clear and the...

X Description: Summary HostsFileParser reloads a changed hosts file by clearing its maps in place and then refilling them. Lookups read those maps without the lock, so a lookup that runs between the clear and the...

Opengraph URL: https://github.com/dnsjava/dnsjava/issues/429

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"HostsFileParser: lookups during a hosts file reload miss existing entries","articleBody":"## Summary\n\n`HostsFileParser` reloads a changed hosts file by clearing its maps in place and then refilling them. Lookups read those maps without the lock, so a lookup that runs between the clear and the refill gets `Optional.empty()` for a name that is in both the old and the new file. The first read of the file has the same window. Since v3.6.4.\n\nImpact: for each lookup that coincides with a reload, `Lookup` falls through to DNS (usually NXDOMAIN) for a name the hosts file defines. The window opens on every reload, and more often the lower `dnsjava.hostsfile.change_check_interval_ms` is and the more threads resolve.\n\nA second, smaller bug in the same code: `isEntireFileParsed` is never reset, so if the file grows past `dnsjava.hostsfile.max_size_bytes` after a full parse, every name not already cached is reported absent until the JVM restarts.\n\n## How it was found\n\n[DNSControl](https://github.com/OpenPojo/dnscontrol) routes JVM-wide DNS through dnsjava's `Lookup` and honours `jdk.net.hosts.file` via `HostsFileParser`. Its quality pass ([OpenPojo/dnscontrol#23](https://github.com/OpenPojo/dnscontrol/issues/23)) added [a concurrency test](https://github.com/OpenPojo/dnscontrol/blob/0c74e4bdba66b8112d847cff880f1e30148cc25e/src/test/java/com/openpojo/dns/HostsFileReloadConcurrencyTest.java): 32 threads run `new Lookup(\"racing.a.test.\", Type.A).run()` while the main thread rewrites the hosts file between two addresses. Every answer must be one of the two addresses. Files are replaced atomically (write aside, `ATOMIC_MOVE`), so half-written files are ruled out, and `dnsjava.hostsfile.change_check_interval_ms=0`.\n\nAgainst dnsjava 3.7.0's parser (macOS, Corretto 21.0.6), runs that failed with a lookup getting no answer:\n\n| Rewrites | Pause between rewrites | Failed runs |\n|---|---|---|\n| 5 | 50 ms | 0 / 8 |\n| 300 | 2 ms | 1 / 5 |\n| 1000 | 0 | 3 / 5 |\n| 3000 | 0 | 8 / 10 |\n\nDNSControl now works around it ([`HostsFileWatcher`](https://github.com/OpenPojo/dnscontrol/blob/0c74e4bdba66b8112d847cff880f1e30148cc25e/src/main/java/com/openpojo/dns/hosts/HostsFileWatcher.java)): it builds a new `HostsFileParser(path, false)`, reads it once, then swaps it into `Lookup` whole. Result: 0 / 20 at 3000 rewrites. We would rather drop that workaround once dnsjava's own reload is safe.\n\n## Root cause\n\nOn `master` ([9e26eba2](https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java)):\n\n1. [`validateCache()` L324-L326](https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L324-L326) returns without the lock while the check interval has not elapsed.\n2. The reloading thread sets [`lastFileModificationCheckTime` (L341)](https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L341) before reading, so every other thread takes that fast path for the whole reload.\n3. [`readHostsFile()` L351](https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L351) calls [`createOrClearCache()` L366-L374](https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L366-L374), which clears the live maps (or, on the first read, publishes new empty ones) before `parseEntireHostsFile()` fills them.\n4. Meanwhile [`getAddressForHost` L115](https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L115) reads the map and finds nothing.\n\n`isEntireFileParsed` is only ever set to `true` ([L356](https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L356)), which is the second bug.\n\nThe unlocked path came from 56099984 (\"Reduce lock contention and disk access in hosts file parsing\", #369), first released in v3.6.4; before it, `getAddressForHost` was `synchronized`. #400 (an NPE on `hostsCache`) is another symptom of the same unlocked read.\n\n## Deterministic reproduction\n\nThree tests in `HostsFileParserTest` (in the PR that follows). The first two pause the reload inside the file read with a spied `FileSystemProvider` (the same technique as the existing `handleNoModificationTime`) and look up in that window, using a mocked `Clock` to stay on the fast path. No sleeps or loops:\n\n- `testLookupDuringReloadFindsUnchangedEntry`: a lookup during a reload must find an entry present in both versions.\n- `testLookupDuringFirstReadWaitsForIt`: a lookup during the first read must wait for it instead of answering from the empty map.\n- `testFileGrownBeyondFullCacheSizeIsSearched`: after a small file is replaced by one over the full-cache limit, names only in the new file must be found.\n\nAgainst `master`'s `HostsFileParser`, all 27 tests run, and only these 3 fail, with no retries, on Corretto 11.0.15, 21.0.6 and 25:\n\n```\norg.xbill.DNS.hosts.HostsFileParserTest.testLookupDuringReloadFindsUnchangedEntry \u003c\u003c\u003c FAILURE!\njava.lang.AssertionError:\nExpecting Optional to contain:\n  kubernetes.docker.internal./127.0.0.1\nbut was empty.\n\norg.xbill.DNS.hosts.HostsFileParserTest.testLookupDuringFirstReadWaitsForIt \u003c\u003c\u003c FAILURE!\njava.lang.AssertionError:\nExpecting Optional to contain:\n  kubernetes.docker.internal./127.0.0.1\nbut was empty.\n\norg.xbill.DNS.hosts.HostsFileParserTest.testFileGrownBeyondFullCacheSizeIsSearched \u003c\u003c\u003c FAILURE!\njava.lang.AssertionError:\nExpecting Optional to contain:\n  localhost-10./127.0.0.10\nbut was empty.\n```\n\nA fix with these tests follows as a PR.\n","author":{"url":"https://github.com/oshoukry","@type":"Person","name":"oshoukry"},"datePublished":"2026-11-02T06:47:38Z","url":"https://github.com/dnsjava/dnsjava/issues/429"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e5e370a3-070b-7866-f3e9-888392dba917
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE200:17E4EA:67F362:8A742A:6B0629DA
html-safe-nonce15094e6e01042109fdde059ba71368e47051cc626708a4fe28828487a120fc4d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjAwOjE3RTRFQTo2N0YzNjI6OEE3NDJBOjZCMDYyOURBIiwidmlzaXRvcl9pZCI6IjY0ODYzNDk5MTgxOTcxMzE3MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac574aa345000a04934525b6fddcff171ec267e0e8d05e1c0129b9b60c95e3fd03
hovercard-subject-tagissue:6157694063
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/dnsjava/dnsjava/429/issue_layout
twitter:imagehttps://opengraph.githubassets.com/a9dc77f4bcb63dbb33929d364f210969912c113a213426576bfd080642ce2dde/dnsjava/dnsjava/issues/429
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/a9dc77f4bcb63dbb33929d364f210969912c113a213426576bfd080642ce2dde/dnsjava/dnsjava/issues/429
og:image:altSummary HostsFileParser reloads a changed hosts file by clearing its maps in place and then refilling them. Lookups read those maps without the lock, so a lookup that runs between the clear and the...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameoshoukry
hostnamegithub.com
expected-hostnamegithub.com
None7f961de5dd5c5d4aca24d33f8b3ffb3fb8b2ef53d0a4f32f01f0a790e512f6d3
turbo-cache-controlno-preview
go-importgithub.com/dnsjava/dnsjava git https://github.com/dnsjava/dnsjava.git
octolytics-dimension-user_id6755615
octolytics-dimension-user_logindnsjava
octolytics-dimension-repository_id17084567
octolytics-dimension-repository_nwodnsjava/dnsjava
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id17084567
octolytics-dimension-repository_network_root_nwodnsjava/dnsjava
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release494ea0bb1e0feef734a83e2628697647755e8864
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/dnsjava/dnsjava/issues/429#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fdnsjava%2Fdnsjava%2Fissues%2F429
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fdnsjava%2Fdnsjava%2Fissues%2F429
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=dnsjava%2Fdnsjava
Reloadhttps://github.com/dnsjava/dnsjava/issues/429
Reloadhttps://github.com/dnsjava/dnsjava/issues/429
Reloadhttps://github.com/dnsjava/dnsjava/issues/429
dnsjavahttps://github.com/dnsjava
dnsjavahttps://github.com/dnsjava/dnsjava
Codehttps://github.com/dnsjava/dnsjava
Issues16 (16)https://github.com/dnsjava/dnsjava/issues
Pull requests3 (3)https://github.com/dnsjava/dnsjava/pulls
Actionshttps://github.com/dnsjava/dnsjava/actions
Security and quality8 (8)https://github.com/dnsjava/dnsjava/security
Insightshttps://github.com/dnsjava/dnsjava/insights
https://github.com/dnsjava/dnsjava
New issuehttps://github.com/login?return_to=https://github.com/dnsjava/dnsjava/issues/429
New issuehttps://github.com/login?return_to=https://github.com/dnsjava/dnsjava/issues/429
#430https://github.com/dnsjava/dnsjava/pull/430
HostsFileParser: lookups during a hosts file reload miss existing entrieshttps://github.com/dnsjava/dnsjava/issues/429#top
#430https://github.com/dnsjava/dnsjava/pull/430
https://github.com/oshoukry
oshoukryhttps://github.com/oshoukry
on Nov 2, 2026https://github.com/dnsjava/dnsjava/issues/429#issue-6157694063
DNSControlhttps://github.com/OpenPojo/dnscontrol
OpenPojo/dnscontrol#23https://github.com/OpenPojo/dnscontrol/issues/23
a concurrency testhttps://github.com/OpenPojo/dnscontrol/blob/0c74e4bdba66b8112d847cff880f1e30148cc25e/src/test/java/com/openpojo/dns/HostsFileReloadConcurrencyTest.java
HostsFileWatcherhttps://github.com/OpenPojo/dnscontrol/blob/0c74e4bdba66b8112d847cff880f1e30148cc25e/src/main/java/com/openpojo/dns/hosts/HostsFileWatcher.java
9e26eba2https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java
validateCache() L324-L326https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L324-L326
lastFileModificationCheckTime (L341)https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L341
readHostsFile() L351https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L351
createOrClearCache() L366-L374https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L366-L374
getAddressForHost L115https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L115
L356https://github.com/dnsjava/dnsjava/blob/9e26eba2832e197d91ba28c91f7a23207faa4726/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java#L356
5609998https://github.com/dnsjava/dnsjava/commit/560999841b5041c76c57605b367aefd75a150620
#369https://github.com/dnsjava/dnsjava/issues/369
#400https://github.com/dnsjava/dnsjava/issues/400
oshoukryhttps://github.com/oshoukry
on Nov 2, 2026https://github.com/dnsjava/dnsjava/issues/429#event-34928741536
dnsjava#429 Coordinate the first-read test with latches instead of po…https://github.com/oshoukry/dnsjava/commit/396fe7330a630996a70cccf6edd7c09b162e2e3b
dnsjava#429https://github.com/dnsjava/dnsjava/issues/429
396fe73https://github.com/oshoukry/dnsjava/commit/396fe7330a630996a70cccf6edd7c09b162e2e3b
ibauersachshttps://github.com/ibauersachs
completedhttps://github.com/dnsjava/dnsjava/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
fe4b7bahttps://github.com/dnsjava/dnsjava/commit/fe4b7bab83e169121c3cfce99b970a2995be2aa4
on Nov 4, 2026https://github.com/dnsjava/dnsjava/issues/429#event-35179354818
ibauersachshttps://github.com/ibauersachs
on Nov 7, 2026https://github.com/dnsjava/dnsjava/issues/429#event-35444460260
Prevent lookups from seeing a hosts file reload in progress (dnsjava#430https://github.com/RaphaelFakhri/dnsjava/commit/fe4b7bab83e169121c3cfce99b970a2995be2aa4
dnsjava#430https://github.com/dnsjava/dnsjava/pull/430
https://docs.github.com/articles/closing-issues-via-commit-messages
fe4b7bahttps://github.com/RaphaelFakhri/dnsjava/commit/fe4b7bab83e169121c3cfce99b970a2995be2aa4
Sign up for freehttps://github.com/signup?return_to=https://github.com/dnsjava/dnsjava/issues/429
Sign in to commenthttps://github.com/login?return_to=https://github.com/dnsjava/dnsjava/issues/429
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.