Skip to content

Fixed the race condition: print dev mode ready message after WatchService registration - #526

Open
sajeerzeji wants to merge 1 commit into
OpenLiberty:mainfrom
sajeerzeji:GHLMP2070-Fix_race_condition_in_DevMojo_doDevMode
Open

Fixed the race condition: print dev mode ready message after WatchService registration#526
sajeerzeji wants to merge 1 commit into
OpenLiberty:mainfrom
sajeerzeji:GHLMP2070-Fix_race_condition_in_DevMojo_doDevMode

Conversation

@sajeerzeji

@sajeerzeji sajeerzeji commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Fixes OpenLiberty/ci.maven#2070

PR Ci.Maven: OpenLiberty/ci.maven#2073
PR Ci.Gradle: OpenLiberty/ci.gradle#1095

In DevUtil.watchFiles(), the "Liberty is running in dev mode." startup banner is now printed after all source, test, config, and resource directories have been registered with the WatchService, but before initWatchLoop() enters the event poll. Previously the banner was emitted by runHotkeyReaderThread() in the callers (ci.maven's DevMojo, ci.gradle's DevTask) before watchFiles() was even called, meaning any file change made immediately after that message by a test or a user could race ahead of the watcher and be silently dropped with no recompile triggered. Moving the print into watchFiles() and checking it in with the existing firstStartup flag makes the ready message a reliable synchronisation point: once a user or test sees it, the WatchService is fully set up and guaranteed to detect changes. The runHotkeyReaderThread() post test run re print path is unchanged.

@turkeylurkey turkeylurkey 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.

.

inputUnavailable.wait(500);
}
printDevModeMessages(inputUnavailable.get(), firstStartup);
firstStartup = false;

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.

Could you explain why we don't need to clear this boolean anymore? The comment says "If the thread is already running..." so it makes me wonder if firstStartup is always false by the time this is called.

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.

The firstStartup is always false by the time runHotkeyReaderThread() is reached. watchFiles() sets firstStartup = false before entering the watch loop via initWatchLoop(). The only call site for runHotkeyReaderThread() in ci.common is inside TestJob.run(), which runs after the watch loop is active, so watchFiles() has always completed by then. The old code reset it here to cover the premature call from DevMojo/DevTask before watchFiles() ran. That premature call is the race condition we are removing, and without it the reset is no longer needed.

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.

Fix race condition in DevMojo.doDevMode()

2 participants