Skip to content

Extra sass-embedded compilers are not disposed #1244

@hikiko4ern

Description

@hikiko4ern

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:

sass-loader/src/utils.js

Lines 764 to 766 in c75c606

// Check again because awaiting the initialization function
// introduces a race condition.
if (!sassModernCompilers.has(webpackCompiler)) {

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

  1. clone https://github.com/hikiko4ern/sass-loader-compiler
  2. run pnpm i
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions