Skip to content

fix(project): Memoize in-flight native watcher load to avoid polling race - #1578

Merged
matz3 merged 1 commit into
mainfrom
fix/watcher-concurrent-native-fallback
Sep 7, 2026
Merged

fix(project): Memoize in-flight native watcher load to avoid polling race#1578
matz3 merged 1 commit into
mainfrom
fix/watcher-concurrent-native-fallback

Conversation

@matz3

@matz3 matz3 commented Sep 7, 2026

Copy link
Copy Markdown
Member

Concurrent subscribe() calls (as issued by WatchHandler via Promise.all) raced on the native-backend memoization: nativeBackendLoaded was flipped to true before the dynamic import() resolved, so callers settling before the winner assigned nativeBackend read a null value and silently fell back to the polling backend. On projects with many watched paths (e.g. the OpenUI5 testsuite), that meant nearly all source watchers polled ~42k files every 250ms, pegging idle CPU at ~250%.

Memoize the in-flight promise instead of a pre-await boolean so concurrent callers await the same import and all observe the resolved backend. Add a regression test that fires concurrent subscribe() calls before the first load resolves and asserts all use the native backend.

…race

Concurrent subscribe() calls (as issued by WatchHandler via Promise.all)
raced on the native-backend memoization: nativeBackendLoaded was flipped
to true before the dynamic import() resolved, so callers settling before
the winner assigned nativeBackend read a null value and silently fell back
to the polling backend. On projects with many watched paths (e.g. the
OpenUI5 testsuite), that meant nearly all source watchers polled ~42k
files every 250ms, pegging idle CPU at ~250%.

Memoize the in-flight promise instead of a pre-await boolean so concurrent
callers await the same import and all observe the resolved backend. Add a
regression test that fires concurrent subscribe() calls before the first
load resolves and asserts all use the native backend.
@matz3
matz3 requested a review from codeworrior September 7, 2026 12:41

@codeworrior codeworrior left a comment

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.

LGTM!

@matz3
matz3 merged commit 073f807 into main Sep 7, 2026
78 checks passed
@matz3
matz3 deleted the fix/watcher-concurrent-native-fallback branch September 7, 2026 13:35
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