threads.js: `pool.terminate()` crashing Electron app

Hello,

thanks for this great library. I really like the syntax and everything seems to be doing exactly what I want. Unfortunately I have an issue with the pool.terminate() command. If I use it, it pretty much every time crashes the Electron Renderer process. Any idea what might be the issue? I don’t get any js/ts error. In the crash reports I can see the following error: EXC_BAD_ACCESS / EXC_I386_GPFLT.

I am on Electron 8.3.0 and using it with Electron Forge 6.0.0-beta.51 and the webpack/typescript/react template.

This is the code and I made sure it’s only run once:

const loadCsvItemModels = async () => {
    const workerPool = Pool(
      () => spawn(new Worker("../../workers/parseStl")));

    filteredItems.forEach((item) => {
      // load stl from csv
      if (item.stl !== undefined && item._sam.model === undefined) {
        if (fs.existsSync(item.stl)) {
          setStoreState({
            type: "SET_ITEM_MODEL_DATA",
            sku: item.sku,
            modelData: { isComputing: true },
          });
          workerPool.queue(async (parseStl: any) => {
            const modelData = await parseStl.getModelData({
              stlPath: item.stl
            });
            storeResults(item.sku, modelData);
          });
        }
      }
    });

    // await workerPool.completed();
    workerPool.terminate();
  };

If I leave out terminate() everything works as expected. Is there any downside/ memory leak possibility if I just leave it out? It seems like the pool is terminating anyway if there is nothing added to the queue after the specified timeout.

Thank you for your help!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Cool! I will look into it as soon as I find some time.

Just as a general note: Of course it shouldn’t crash the process either way, but think twice if you really need the nodeIntegrationInWorker as it’s a really bad decision from an app security point of view 😉