Skip to content

Sync API fails with "Invalid protobuf" errors on Node 24.22 for large outputs #451

Closed
sass/sync-child-process
#38

Description

@Jealrock

Since Node 24.22.0, the synchronous API (initCompiler().compile()) fails on Linux x64 (glibc) with Compiler caused error: Invalid protobuf: ... when the compiled CSS is large. The async API (compileAsync) works fine on the same input. Node 24.21.0 and earlier work with both APIs.

node_modules/sass-embedded/dist/lib/src/compiler/sync.js:158
                    throw error;
                    ^

Error: Compiler caused error: Invalid protobuf: Error: illegal tag: field no 13 wire type 6.
    at compilerError (node_modules/sass-embedded/dist/lib/src/utils.js:91:12)
    at decode (node_modules/sass-embedded/dist/lib/src/message-transformer.js:105:41)
    at node_modules/rxjs/dist/cjs/internal/operators/map.js:10:37
    ...
Reproduction

repro.js:

const fs = require('fs');
const sass = require('sass-embedded');

// ~2.5 MB of CSS output
fs.writeFileSync('big.scss', Array.from({ length: 100000 }, (_, i) => .c${i} { color: red; }).join('\n'));

async function main() {
  console.log(node ${process.version}, sass ${sass.info.replace(/\s+/g, ' ')});

  for (let i = 1; i <= 5; i++) {
    const compiler = sass.initCompiler();
    try {
      console.log(sync  #${i}: ok, ${compiler.compile('big.scss').css.length} bytes);
    } catch (e) {
      console.log(sync  #${i}: ${e.message.split('\n')[0]});
    } finally {
      compiler.dispose();
    }
  }

  for (let i = 1; i <= 5; i++) {
    try {
      console.log(async #${i}: ok, ${(await sass.compileAsync('big.scss')).css.length} bytes);
    } catch (e) {
      console.log(async #${i}: ${e.message.split('\n')[0]});
    }
  }
}

main();

Then run with:

docker run --rm -v "$PWD":/w -w /w node:24.22.0 \
  bash -c 'npm i --silent --no-save [email protected] && node repro.js'

Output size matters. Using generated files of the form .c0{color:red} .c1{color:red} ... with an increasing number of rules (5 sync compilations per size):

| Rules   | Output size | Sync successes |
| ------- | ----------- | -------------- |
| 20,000  | ~500 KB     | 5/5            |
| 30,000  | ~750 KB     | 3/5            |
| 40,000  | ~1 MB       | 1/5            |
| 60,000  | ~1.5 MB     | 1/5            |
| 100,000 | ~2.5 MB     | 0/5            |

Activity

  1. ntkme commented on Oct 22, 2026

    @ntkme
    Contributor

    I'm getting slightly different result but this is reproducible: I'm seeing that both sync and async APIs are failing when output is very large.

    • Sync: Compiler caused error: Embedded compiler exited unexpectedly.
    • Async: Dispatcher closed before compilation completed

    I can reproduce it on linux (both glibc and musl-libc), but not on mac. I didn't get a chance to test windows.

    Also, I can reproduce this compiler crash with ruby sass-embedded on linux, so that this is likely a problem on dart side, rather than on node side.

  2. ntkme commented on Oct 22, 2026

    @ntkme
    Contributor

    After some digging what I noticed is that on my podman linux VM where I was able to reproduce this, compiling a 9.7MB input is causing compiler to get OOM killed on the 2GB memory VM. The problem is the excessive memory usage in Dart VM.

    [517685.213330] Out of memory: Killed process 1049661 (dart:sass.snaps) total-vm:2012732kB, anon-rss:1501936kB, file-rss:100kB, shmem-rss:0kB, UID:0 pgtables:3132kB oom_score_adj:0
    

    @Jealrock I see that the reproduction you provided is using docker. Do you know how much memory your host os (if on linux) or docker linux vm (if on mac) or if the container has explicit memory limit?

  3. ntkme commented on Oct 22, 2026

    @ntkme
    Contributor

    I tried it again and now I can reproduce Compiler caused error: Invalid protobuf: Error: illegal tag: field no 13 wire type 6. error, and this appears to have a different root cause than OOM crash.

  4. ntkme commented on Oct 23, 2026

    @ntkme
    Contributor

    I found the root cause: https://github.com/sass-contrib/sync-child-process/blob/ea3886972cca7e0b22515a4db0cbcffb5d47cd7a/lib/index.ts#L107

    The Buffer.from(message.data.buffer) sometimes returns a corrupted copy the buffer, and this is documented at https://nodejs.org/api/buffer.html#bufbuffer:

    This ArrayBuffer is not guaranteed to correspond exactly to the original Buffer.


    I added a debug message as:

    diff --git a/lib/index.ts b/lib/index.ts
    index eff4515..d3f32b0 100644
    --- a/lib/index.ts
    +++ b/lib/index.ts
    @@ -104,6 +104,7 @@ export class SyncChildProcess implements Iterator<
         switch (message.type) {
           case 'stdout':
             return {
    +          console.log(Buffer.from(message.data.buffer).equals(message.data));
               value: {type: 'stdout', data: Buffer.from(message.data.buffer)},
             };
     

    What I see is that Buffer.from(message.data.buffer) is occasionally creating a copy that is not equal to original message.data.

  5. ntkme commented on Oct 23, 2026

    @ntkme
    Contributor

    I opened sass/sync-child-process#38 which should fix this bug.

  6. Jealrock commented on Oct 23, 2026

    @Jealrock
    Author

    @ntkme thanks for quick response! I tried the suggested fix and it worked 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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