Fix #12912: assign FastTerminal before starting the build thread - #12961
Merged
Conversation
The FastTerminal constructor started the build thread before returning, so MessageUtils.terminal was still null when the build thread ran the builder callback — a race between the constructor returning and the thread scheduling. Split construction from start: MessageUtils now assigns the field before calling FastTerminal.start(), and Thread.start() provides the happens-before edge that makes the assignment visible to the build thread. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
gnodet
commented
Aug 30, 2026
gnodet
left a comment
Contributor
Author
There was a problem hiding this comment.
Correct fix for a real race condition. The constructor-starts-thread-before-field-assignment pattern was a textbook publish-before-init bug, and separating construction from start() is the right approach.
Highlights:
- The JMM analysis is sound:
Thread.start()establishes a happens-before edge (JLS 17.4.4), so the prior assignment toMessageUtils.terminalis guaranteed visible to the build thread withoutvolatile. - The test
terminalAssignmentIsVisibleFromBuilderCallbackcorrectly exercises the invariant. - The diff is identical to the forward port #12962 targeting master — the two PRs are in sync.
Minor suggestion (non-blocking):
- The new
start()method ispublic, but its only caller isMessageUtils.systemInstall()in the same package. Package-private visibility would narrow the API surface. (LookupInvokeronly callsgetTerminal(), notstart().)
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a race condition introduced in #12921: the
FastTerminalconstructor started its build thread before returning, soMessageUtils.terminalwas stillnullwhen the build thread ran the builder callback — a race between the constructor returning and the thread scheduling. This caused aNullPointerExceptionin CI (example):The fix splits construction from start:
MessageUtilsnow assigns the field before callingFastTerminal.start(), andThread.start()provides the happens-before edge that makes the assignment visible to the build thread without additional synchronization.FastTerminal: extractstart()method from constructor, document the publish-before-start contractMessageUtils.systemInstall(): assignterminalfield, then callstart()terminalAssignmentIsVisibleFromBuilderCallbackthat assertsMessageUtils.getTerminal()is non-null from the builder callbackTest plan
FastTerminalReentrancyTest— all 5 tests pass (4 existing + 1 new)maven-jlinemodule test suite passes🤖 Generated with Claude Code