Skip to content

Commit 4f16f17

Browse files
fix(workspace): keep the install's SIGKILL timers referenced; name shadowing only on a real version
An unref'd timer never fires in a process draining its loop, and the SIGKILL is the only thing that ends a descendant that ignored SIGTERM — both the deadline's escalation and the post-exit sweep stay referenced; five seconds of loop is the price. And a binary first on PATH that reports no version is not evidence of shadowing: say what was observed and leave the diagnosis to a real, older version.
1 parent 68dcce4 commit 4f16f17

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

‎packages/opencode/src/altimate/workspace/engine-offer.ts‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,24 @@ export function runInstall(
200200
killTree("SIGTERM")
201201
hard = setTimeout(() => {
202202
// The group outlives its leader while any member is alive, so this
203-
// reaches survivors even after npm itself has exited. Unref'd: it must
204-
// not keep the process alive once the run has already resolved.
203+
// reaches survivors even after npm itself has exited. Referenced on
204+
// purpose: an unref'd timer never fires in a process that is draining
205+
// its loop, and the SIGKILL is the only thing that ends a descendant
206+
// that ignored SIGTERM — five seconds of loop is the price.
205207
killTree("SIGKILL")
206208
finish(null)
207-
}, graceMs).unref()
209+
}, graceMs)
208210
}, timeoutMs)
209211
child.once("exit", (code) => {
210212
finish(code)
211213
// npm is done, but a descendant it forked may still be alive in the
212214
// group (a lifecycle script's daemon). It is the install's straggler,
213215
// not the user's: reap it — SIGTERM now, SIGKILL after the grace —
214-
// without holding the result or this process for it.
216+
// without holding the result for it. The timer stays referenced for
217+
// the same reason the deadline's does: it must actually fire.
215218
if (!timedOut && grouped) {
216219
killTree("SIGTERM")
217-
setTimeout(() => killTree("SIGKILL"), graceMs).unref()
220+
setTimeout(() => killTree("SIGKILL"), graceMs)
218221
}
219222
})
220223
child.once("error", (err) => {
@@ -244,15 +247,23 @@ export async function installEngine(): Promise<InstallResult> {
244247
}
245248
}
246249
const installedVersion = await versionOf(installedBin)
250+
if (!installedVersion) {
251+
// Could not run or did not answer: say what was observed, no diagnosis.
252+
return {
253+
ok: false,
254+
error:
255+
`npm installed it, but the ${ENGINE_BINARY} first on PATH (${installedBin}) did not report a version — ` +
256+
`try \`${ENGINE_BINARY} --version\` there before retrying`,
257+
}
258+
}
247259
if (!clearsFloor(installedVersion)) {
248-
// The likeliest cause is not a bad install: an older engine earlier on
249-
// PATH shadows the one npm just wrote.
260+
// A real, older version first on PATH: an earlier install shadows the
261+
// one npm just wrote.
250262
return {
251263
ok: false,
252264
error:
253-
`npm installed it, but the ${ENGINE_BINARY} first on PATH (${installedBin}) reports ` +
254-
`${installedVersion ?? "no version"} — an older install earlier on PATH is shadowing the new one; ` +
255-
`remove it, or put npm's global bin directory ahead of it`,
265+
`npm installed it, but the ${ENGINE_BINARY} first on PATH (${installedBin}) reports ${installedVersion} — ` +
266+
`an older install earlier on PATH is shadowing the new one; remove it, or put npm's global bin directory ahead of it`,
256267
}
257268
}
258269
return { ok: true }

0 commit comments

Comments
 (0)