Skip to content

Commit ea10930

Browse files
committed
Another attempt to streamline process handlign for preview on Windows
1 parent 6b1a8d2 commit ea10930

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

programs/develop/webpack/dev-server/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ function closeAll(devServer: RspackDevServer, portManager: PortManager) {
2929
.then(async () => {
3030
// Terminate the current instance
3131
await portManager.terminateCurrentInstance()
32-
process.exit()
32+
// Allow browser plugin signal handlers to complete cleanup
33+
setTimeout(() => process.exit(), 500)
3334
})
3435
.catch(async (error) => {
3536
console.log(messages.extensionJsRunnerError(error))
3637
// Still try to terminate the instance
3738
await portManager.terminateCurrentInstance()
38-
process.exit(1)
39+
// Allow browser plugin signal handlers to complete cleanup
40+
setTimeout(() => process.exit(1), 500)
3941
})
4042
}
4143

@@ -291,10 +293,8 @@ export async function devServer(
291293
await cleanup()
292294
}
293295

294-
process.removeAllListeners?.('SIGINT')
295-
process.removeAllListeners?.('SIGTERM')
296-
process.removeAllListeners?.('SIGHUP')
297-
process.removeAllListeners?.('ERROR')
296+
// Do not remove other listeners; let browser plugins receive signals too.
297+
// Register our cleanup alongside theirs so Ctrl+C terminates the browser.
298298
process.on('ERROR', cancelAndCleanup)
299299
process.on('SIGINT', cancelAndCleanup)
300300
process.on('SIGTERM', cancelAndCleanup)

programs/develop/webpack/plugin-browsers/run-chromium/chromium-launch/process-handlers.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ChildProcess} from 'child_process'
1+
import {ChildProcess, spawn} from 'child_process'
22
import * as messages from '../../browsers-lib/messages'
33
import type {DevOptions} from '../../../webpack-types'
44

@@ -14,6 +14,20 @@ export function setupProcessSignalHandlers(
1414
}
1515

1616
if (child && !child.killed) {
17+
// On Windows, ensure the entire process tree is terminated.
18+
// Chromium spawns multiple processes; taskkill /T /F is most reliable.
19+
if (process.platform === 'win32') {
20+
try {
21+
spawn('taskkill', ['/PID', String(child.pid), '/T', '/F'], {
22+
stdio: 'ignore',
23+
windowsHide: true
24+
}).on('error', () => {
25+
// Ignore errors from taskkill
26+
})
27+
} catch {
28+
// Ignore
29+
}
30+
}
1731
if (process.env.EXTENSION_ENV === 'development') {
1832
console.log(messages.enhancedProcessManagementTerminating(browser))
1933
}

0 commit comments

Comments
 (0)