Skip to content

Fix typespec-java emitter build hanging parallel pnpm build - #5004

Merged
timotheeguerin merged 1 commit into
mainfrom
fix-java-hang
Jul 22, 2026
Merged

Fix typespec-java emitter build hanging parallel pnpm build#5004
timotheeguerin merged 1 commit into
mainfrom
fix-java-hang

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Problem

A full-repo pnpm build intermittently hangs at the Java emitter build. The output stops right after:

@azure-tools/typespec-java:build: core-commit.json SHA ... using current checkout.

and never reaches Copy generator sources from core. Building packages/typespec-java on its own always works. Prior attempts (#4972, #4983, and non-interactive/fetch hardening) did not resolve it.

Root cause

turbo runs each task's process in its own background process group under the build's controlling terminal (the TUI). When a PowerShell cmdlet renders Write-Progress — which Copy-Item -Recurse in Copy-Sources.ps1 does — pwsh touches that terminal from a background process group and the OS stops the process with SIGTTIN/SIGTTOU (T state). It never resumes, so the build hangs forever.

This explains all the symptoms:

  • Java-only: it is the only package that shells out to pwsh.
  • Intermittent: Copy-Item only renders progress when the copy is slow enough (under parallel-build load).
  • Invisible when piped / in isolation: with piped output (no TUI) or a standalone build, pwsh is not a background process group of a controlling terminal, so nothing stops it.
  • Unaffected by -NonInteractive: progress renders regardless.

Reproduced directly: a pwsh running Write-Progress in a background process group under a controlling tty immediately enters T (stopped); with $ProgressPreference = 'SilentlyContinue' it never stops.

Fix

  • Set $ProgressPreference = 'SilentlyContinue' in Copy-Sources.ps1, Build-Generator.ps1, and CoreCommit.ps1 so no cmdlet touches the controlling terminal. This is the actual fix.

Complementary hardening (removes secondary hang/network vectors):

  • CoreCommit.ps1: only git fetch the pinned core commit when it is genuinely missing locally (git cat-file -e <sha>^{commit} first) — previously it hit the network on every emitter build / doc regen.
  • CoreCommit.ps1: GIT_TERMINAL_PROMPT=0 and pwsh -NonInteractive (package.json) so a git credential/host prompt can never block the headless build.
  • CoreCommit.ps1: extract pinned sources with [System.IO.Compression.ZipFile]::ExtractToDirectory instead of the pathologically slow Expand-Archive.

Verification

  • Reproduced the T-state stop with Write-Progress under a controlling tty; confirmed $ProgressPreference='SilentlyContinue' prevents it.
  • 8/8 runs of the real Copy-Sources.ps1 in a background process group under a controlling tty never stop.
  • Full pnpm build completes 63/63; git -C core status stays clean.

…SIGTTOU)

The Java emitter build intermittently hung a full `pnpm build`, stopping
right after "using current checkout" and never printing "Copy generator
sources from core".

Root cause: turbo runs each task in its own background process group under
the build's controlling terminal. When a PowerShell cmdlet renders
Write-Progress (notably `Copy-Item -Recurse` in Copy-Sources.ps1), pwsh
touches that terminal from a background process group and the OS stops the
process with SIGTTIN/SIGTTOU -- it never resumes, so the build hangs
forever. It only affects typespec-java (the sole package that shells out to
pwsh) and is intermittent (progress only renders when the copy is slow
enough under load), which is why it survived earlier fix attempts and is
invisible when output is piped.

Fix: set `$ProgressPreference = 'SilentlyContinue'` in the .ps1 build
scripts so no cmdlet touches the terminal. Also harden the pinned-core read:
only `git fetch` when the commit is missing locally, and make git/pwsh
non-interactive (GIT_TERMINAL_PROMPT=0, `pwsh -NonInteractive`) so a prompt
can never block the headless build. Extract archives with
ZipFile.ExtractToDirectory instead of the slow Expand-Archive.
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:java Issues for @azure-tools/typespec-java emitter label Jul 21, 2026
@azure-sdk-automation

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-java
Show changes

@azure-tools/typespec-java - internal ✏️

Fix the Java emitter build intermittently hanging a full parallel pnpm build. The build scripts run under turbo, which puts each task in a background process group under the build's controlling terminal; when a PowerShell cmdlet (notably Copy-Item -Recurse) rendered Write-Progress, pwsh touched that terminal and the OS stopped it with SIGTTIN/SIGTTOU, hanging forever. The .ps1 build scripts now set $ProgressPreference = 'SilentlyContinue'. Also make the pinned-core/ fetch conditional (only when the commit is missing) and non-interactive (GIT_TERMINAL_PROMPT=0, pwsh -NonInteractive) to remove secondary hang/network vectors.

@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-java@5004

commit: cb93f66

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

@timotheeguerin
timotheeguerin added this pull request to the merge queue Jul 22, 2026
Merged via the queue into main with commit 0b9a230 Jul 22, 2026
30 checks passed
@timotheeguerin
timotheeguerin deleted the fix-java-hang branch July 22, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:java Issues for @azure-tools/typespec-java emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants