Bug report
When using the sass-embedded with the modern-compiler API, sass-loader may create multiple compilers (= make multiple initAsyncCompiler calls). Before the created compiler is saved to sassModernCompilers, there is a check to handle race conditions:
https://github.com/webpack-contrib/sass-loader/blob/c75c6061266a6df6a7c736de407fcbf05ef5b2be/src/utils.js#L764-L766
But in the case when sassModernCompilers.has(webpackCompiler) === true, the newly created compiler is not disposed (i.e. compiler.dispose() is not called), causing sass-embedded to never shut down the dart sass.snapshot --embedded process it started, causing the Node.js process to never exit due to alive child_processes.
Actual Behavior
Node.js process does not exit due to alive child processes
Expected Behavior
If sassModernCompilers already has a compiler, should compiler.dispose() be called for the newly created compiler? Something like
if (!sassModernCompilers.has(webpackCompiler)) {
sassModernCompilers.set(webpackCompiler, compiler);
webpackCompiler.hooks.shutdown.tap("sass-loader", () => {
compiler.dispose();
});
-}
+} else {
+ compiler.dispose();
+}
How Do We Reproduce?
Unfortunately, even on our closed project with a large number of files, the bug does not reproduce consistently. But it can be easily reproduced by adding a small delay: https://github.com/hikiko4ern/sass-loader-compiler/blob/master/patches/sass-loader.patch
- clone https://github.com/hikiko4ern/sass-loader-compiler
- run
pnpm i
- run
pnpm webpack
It should hang after
webpack 5.95.0 compiled successfully in 233 ms
Please paste the results of npx webpack-cli info here, and mention other relevant information
System:
OS: Linux 5.15 Debian GNU/Linux trixie/sid
CPU: (32) x64 AMD Ryzen 9 7950X3D 16-Core Processor
Memory: 53.94 GB / 64.76 GB
Binaries:
Node: 22.11.0 - /run/user/1000/fnm_multishells/1007232_1730374215459/bin/node
npm: 10.9.0 - /run/user/1000/fnm_multishells/1007232_1730374215459/bin/npm
Packages:
sass-loader: ^16.0.2 => 16.0.2
webpack: ^5.95.0 => 5.95.0
webpack-cli: ^5.1.4 => 5.1.4
Bug report
When using the
sass-embeddedwith themodern-compilerAPI,sass-loadermay create multiple compilers (= make multipleinitAsyncCompilercalls). Before the created compiler is saved tosassModernCompilers, there is a check to handle race conditions:https://github.com/webpack-contrib/sass-loader/blob/c75c6061266a6df6a7c736de407fcbf05ef5b2be/src/utils.js#L764-L766
But in the case when
sassModernCompilers.has(webpackCompiler) === true, the newly createdcompileris not disposed (i.e.compiler.dispose()is not called), causingsass-embeddedto never shut down thedart sass.snapshot --embeddedprocess it started, causing the Node.js process to never exit due to alivechild_processes.Actual Behavior
Node.js process does not exit due to alive child processes
Expected Behavior
If
sassModernCompilersalready has a compiler, shouldcompiler.dispose()be called for the newly created compiler? Something likeif (!sassModernCompilers.has(webpackCompiler)) { sassModernCompilers.set(webpackCompiler, compiler); webpackCompiler.hooks.shutdown.tap("sass-loader", () => { compiler.dispose(); }); -} +} else { + compiler.dispose(); +}How Do We Reproduce?
Unfortunately, even on our closed project with a large number of files, the bug does not reproduce consistently. But it can be easily reproduced by adding a small delay: https://github.com/hikiko4ern/sass-loader-compiler/blob/master/patches/sass-loader.patch
pnpm ipnpm webpackIt should hang after
Please paste the results of
npx webpack-cli infohere, and mention other relevant information