Skip to content

npm oxc-parser: importing package in Node worker thread leads to heap corruption error on Windows #14732

@b-strauss

Description

@b-strauss

Hi, importing the npm oxc-parser package in node worker threads sometimes leads to a heap corruption error on Windows.

This bug was discovered after updating from oxc-parser 0.92.0 to 0.95.0.
The used binary package is @oxc-parser/binding-win32-x64-msvc.

If the await import('oxc-parser'); line is commented out, the workers exit normally.
If the module is imported, most of the time, the whole process crashes.
Getting the last exit code with echo $LastExitCode in Powershell returns -1073740940, which is identified as:

# for hex 0xc0000374 / decimal -1073740940
  STATUS_HEAP_CORRUPTION                                         ntstatus.h
# A heap has been corrupted.
# 1 matches found for "C0000374"

by the Microsoft Error Lookup Tool.

Reproduction:

main.mjs

import { dirname, join } from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { Worker } from 'node:worker_threads';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const WORKER_COUNT = 16;
let done = 0;

console.log(`Starting ${ WORKER_COUNT } workers...\n`);

for (let i = 1; i <= WORKER_COUNT; i++) {
   const worker = new Worker(join(__dirname, 'worker.mjs'), {
      workerData: { workerId: i },
   });

   const id = String(i).padStart(2);

   worker.on('error', (error) => {
      console.error(`[Main] Worker ${ id } error:`, error);
   });

   worker.on('exit', (code) => {
      done++;
      if (code !== 0) {
         console.error(`[Main] Worker ${ id } stopped with exit code ${ code }`);
      }
      console.log(`Workers done: ${ done }/${ WORKER_COUNT }`);
      if (done === WORKER_COUNT) {
         console.log(`All workers done!`);
      }
   });
}

process.on('exit', (code) => {
   console.log(`About to exit with code: ${ code }`);
});

console.log(`\n${ WORKER_COUNT } workers created and running!\n`);

worker.mjs

import { workerData } from 'node:worker_threads';

const workerId = String(workerData.workerId);

console.log(`Worker ${ workerId.padStart(2) } starting ...`);

try {
   // When running this import, the worker process fails, which leads to a crash of the main process.
   // If you comment out the import, the worker process runs successfully.
   const module = await import('oxc-parser');
} catch (error) {
   console.error(error);
}

setTimeout(() => {
   console.log(`Hello from worker ${ workerId }`);
}, Math.random() * 1000);

Metadata

Metadata

Assignees

Labels

A-parserArea - ParserC-bugCategory - Bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions