From 85fee00b9ed95e51b07acda14140c89f1655d563 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Mon, 8 Jan 2024 22:04:09 +0100 Subject: [PATCH 1/4] investigate ci hangs --- rollup-exit-plugin.js | 44 +++++++++++++++++++++++++++++++++++++++++++ rollup.config.ts | 2 ++ 2 files changed, 46 insertions(+) create mode 100644 rollup-exit-plugin.js diff --git a/rollup-exit-plugin.js b/rollup-exit-plugin.js new file mode 100644 index 00000000..95631c12 --- /dev/null +++ b/rollup-exit-plugin.js @@ -0,0 +1,44 @@ +let runningBundles = 0; + +/** + * @param {string} name + * @param {number} maxWaitTime Maximum number of seconds to wait for Rollup to exit before force-exiting + * @returns {{closeBundle(): void, buildStart(): void, name: string}} + */ +export const rollupForceExit = (name, maxWaitTime = 60) => { + return { + /** @this {import('rollup').PluginContext} */ + buildStart() { + if (this.meta.watchMode) { + return; + } + + runningBundles++; + this.info(`${name}: Starting build, ${runningBundles} build(s) running`); + }, + /** @this {import('rollup').PluginContext} */ + closeBundle() { + if (this.meta.watchMode) { + return; + } + + runningBundles--; + const timeout = setTimeout(() => { + if (runningBundles === 0) { + this.info( + `${name}: Rollup is now done, but did not exit before ${maxWaitTime} seconds, force exiting...`, + ); + process.exit(0); + } else { + this.info( + `${name}: Rollup is still working on another build process, waiting for ${runningBundles} running bundle(s) before force exit`, + ); + } + }, maxWaitTime * 1000); + // Allow the NodeJS process to finish without waiting for the timeout, using it only as a fallback for + // otherwise hanging Rollup processes + timeout.unref(); + }, + name: 'force-close', + }; +}; diff --git a/rollup.config.ts b/rollup.config.ts index 86e21935..3cfe0093 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -3,6 +3,7 @@ import terser from '@rollup/plugin-terser'; import resolve from '@rollup/plugin-node-resolve'; import commonJS from '@rollup/plugin-commonjs'; import typescript from '@rollup/plugin-typescript'; +import { rollupForceExit } from './rollup-exit-plugin.js'; export default defineConfig({ input: 'src/cli.ts', @@ -26,5 +27,6 @@ export default defineConfig({ commonJS(), resolve(), typescript(), + rollupForceExit('rollup-build', 5), ], }); From 883b4889c9ea0c48e139583c94042de6c926bd00 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Mon, 8 Jan 2024 22:06:38 +0100 Subject: [PATCH 2/4] log why --- package.json | 3 ++- rollup-exit-plugin.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0d4c9fb2..f667fdd4 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "vscode-languageserver-protocol": "^3.17.5", "vscode-languageserver-textdocument": "1.0.11", "vscode-uri": "^3.0.8", - "which": "^4.0.0" + "which": "^4.0.0", + "why-is-node-running": "^2.2.2" } } diff --git a/rollup-exit-plugin.js b/rollup-exit-plugin.js index 95631c12..10464343 100644 --- a/rollup-exit-plugin.js +++ b/rollup-exit-plugin.js @@ -1,3 +1,5 @@ +import whyIsNodeRunning from 'why-is-node-running'; + let runningBundles = 0; /** @@ -28,7 +30,8 @@ export const rollupForceExit = (name, maxWaitTime = 60) => { this.info( `${name}: Rollup is now done, but did not exit before ${maxWaitTime} seconds, force exiting...`, ); - process.exit(0); + whyIsNodeRunning(); + setTimeout(() => process.exit(0)); } else { this.info( `${name}: Rollup is still working on another build process, waiting for ${runningBundles} running bundle(s) before force exit`, From 9b109fa44e2fbb349b299174d91873f9eab077c9 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Mon, 8 Jan 2024 22:16:04 +0100 Subject: [PATCH 3/4] test --- rollup.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup.config.ts b/rollup.config.ts index 3cfe0093..9a4c4f5c 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -27,6 +27,6 @@ export default defineConfig({ commonJS(), resolve(), typescript(), - rollupForceExit('rollup-build', 5), + rollupForceExit('rollup-build2', 5), ], }); From ef9d97cd4a9e7d2421cbca513ca65f9cd7b06282 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Mon, 8 Jan 2024 22:17:41 +0100 Subject: [PATCH 4/4] reproduce please --- rollup.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup.config.ts b/rollup.config.ts index 9a4c4f5c..3cfe0093 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -27,6 +27,6 @@ export default defineConfig({ commonJS(), resolve(), typescript(), - rollupForceExit('rollup-build2', 5), + rollupForceExit('rollup-build', 5), ], });