Skip to content

Fix directory watcher - #1234

Merged
jglogan merged 18 commits into
apple:mainfrom
JaewonHur:fix-directory-watcher-tmp
Feb 25, 2026
Merged

jglogan merged 18 commits into
apple:mainfrom
JaewonHur:fix-directory-watcher-tmp

Conversation

@JaewonHur

Copy link
Copy Markdown
Contributor

Current DirectoryWatcher fails if /etc/resolver does not exist. This PR fixes DirectoryWatcher to handle non-existing /etc/resolver directory. If that directory does not exist, it first watches /etc directory to check if /etc/resolver directory is created later. Once it detects new /etc/resolver directory, it starts watching new DNS resolver files there.

This PR also fixes to log the exception thrown by API server's tasks.

Resolves #1207

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

In case of non-existing /etc/resolver starting API server fails.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

In case of target directory doesn't exist, watch the parent directory
first, and start watching the target directory if it is created. Throw
error if parent directory doesn't exist.
@JaewonHur
JaewonHur requested a review from jglogan February 20, 2026 17:22
DispatchSource.eventHandler and polling loop have a race on `source`.
While it is benign in this case, synchronize for better example.

On the other hand, `LocalhostDNSHandler.dns` is not under race as
`DispatchSource.dispatchQueue` serializes the handler executions.
@jglogan jglogan added this to the 2026-02 milestone Feb 24, 2026
private let watcher: DirectoryWatcher

private var dns: [String: IPv4]
nonisolated(unsafe) private var dns: [String: IPv4]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nonisolated(unsafe) says that the type is protected against concurrent access some other way? Is that the case here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to use mutex. Thanks!

@jglogan
jglogan merged commit 0760791 into apple:main Feb 25, 2026
3 checks passed
jianliang00 pushed a commit to jianliang00/container that referenced this pull request Aug 28, 2026
- Current DirectoryWatcher fails if `/etc/resolver` does not exist. This
  PR fixes DirectoryWatcher to handle non-existing `/etc/resolver`
  directory. If that directory does not exist, it first watches `/etc`
  directory to check if `/etc/resolver` directory is created later. Once
  it detects new `/etc/resolver` directory, it starts watching new DNS
  resolver files there.
- This PR also fixes to log the exception thrown by API server's tasks.
- Closes apple#1207
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.

[Bug]: Directory monitor for localhost DNS fails if no resolver directory.

2 participants