Skip to content

Fall back to inotify when filesystem has errors in fanotify (fix watch in Docker)#4661

Open
johnfav03 wants to merge 1 commit into
microsoft:mainfrom
johnfav03:johnfav03/fix-docker-watch
Open

Fall back to inotify when filesystem has errors in fanotify (fix watch in Docker)#4661
johnfav03 wants to merge 1 commit into
microsoft:mainfrom
johnfav03:johnfav03/fix-docker-watch

Conversation

@johnfav03

Copy link
Copy Markdown
Contributor

Fixes microsoft/TypeScript#63646

Some filesystems, notably Docker bind mounts on macOS and Docker containers' root filesystems, don't implement name_to_handle_at. This is an issue because we default to fanotify for Linux environments, but in these Docker filesystems every fanotify_mark fails with EOPNOTSUPP, so none of the directory watches are ever registered. This results in the initial build succeeding, but subsequent file changes not being detected.

In the fix, when the backend defaults to fanotify and ReconcileWatches fails with ErrFilesystemUnspported, WatchManager closes any existing watches, switches to an inotify backend, and re-registers the desired watch set.

Copilot AI review requested due to automatic review settings July 16, 2026 21:38

Copilot AI left a comment

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.

Pull request overview

Adds automatic inotify fallback when fanotify cannot watch Docker-backed filesystems.

Changes:

  • Introduces an unsupported-filesystem sentinel error.
  • Tags relevant fanotify failures and switches the watch manager to inotify.
  • Adds focused fallback and error-propagation tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/fswatch/watcher.go Defines the filesystem-support error.
internal/fswatch/fanotify_linux.go Classifies unsupported filesystem errors.
internal/fswatch/fanotify_linux_test.go Tests error classification and propagation.
internal/execute/watchmanager/watchmanager.go Implements backend fallback and watch re-registration.
internal/execute/watchmanager/watchmanager_fallback_test.go Tests fallback behavior and production wiring.

}

func maybeWrapUnsupportedFilesystem(err error) error {
if errors.Is(err, unix.EOPNOTSUPP) || errors.Is(err, unix.ENOTSUP) || errors.Is(err, unix.ENODEV) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hm, I guess this comes down to cross-mount watching?

Won't this totally disable the method whenever we detect any unsupported watch?

I do wonder if there's instead some hybrid backend we can do that falls back to inotify for dirs we seemingly can't fanotify.

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.

tsc --watch does not work in docker

3 participants