[clsi] Fix compile stop detection in local runner (#33024)

* [clsi] Fix compile stop detection in local runner

* Tighten compilation cancelled message

* Cleanup process PID on `error`

GitOrigin-RevId: 61495466b98c127402b256d629ea58e7b9be6df7
This commit is contained in:
Miguel Serrano
2026-05-27 11:20:31 +02:00
committed by Copybot
parent 8ce9d184cb
commit 4cfaea4621
2 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ describe('SandboxedCompiles', function () {
stopCompile({ delay: 1000 })
cy.findByRole('region', { name: 'PDF preview' })
.invoke('text')
.should('match', /No PDF|PDF Rendering Error|Compilation cancelled/)
.should('match', /Compilation cancelled/)
// Check that the previous compile is not running in the background by
// disabling the infinite loop and recompiling
cy.findByText('\\def').parent().click()
+10 -2
View File
@@ -20,6 +20,11 @@ let CommandRunner
logger.debug('using standard command runner')
// Track PIDs that have been intentionally killed so that the close handler
// can detect termination even when the child exits with a numeric code instead
// of being reported as killed by a signal (e.g. exit code 4 from latexmk).
const killedPids = new Set()
export default CommandRunner = {
run(
projectId,
@@ -67,6 +72,7 @@ export default CommandRunner = {
proc.stdout.setEncoding('utf8').on('data', data => (stdout += data))
proc.on('error', function (err) {
killedPids.delete(proc.pid)
logger.err(
{ err, projectId, command, directory },
'error running command'
@@ -77,8 +83,8 @@ export default CommandRunner = {
proc.on('close', function (code, signal) {
let err
logger.debug({ code, signal, projectId }, 'command exited')
if (signal === 'SIGTERM') {
// signal from kill method below
const wasKilled = killedPids.delete(proc.pid)
if (signal === 'SIGTERM' || wasKilled) {
err = new Error('terminated')
err.terminated = true
return callback(err)
@@ -100,8 +106,10 @@ export default CommandRunner = {
callback = function () {}
}
try {
killedPids.add(pid)
process.kill(-pid) // kill all processes in group
} catch (err) {
killedPids.delete(pid)
return callback(err)
}
return callback()