Skip to content

onnxruntime-node crash the electron app[Web] #13086

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
MountainAndMorning opened this issue Sep 24, 2022 · 3 comments
Open

onnxruntime-node crash the electron app[Web] #13086

MountainAndMorning opened this issue Sep 24, 2022 · 3 comments
Labels
platform:web issues related to ONNX Runtime web; typically submitted using template

Comments

@MountainAndMorning
Copy link

Describe the issue

I use the onnxruntime-node in the electron app with web worker. When I first create the web worker, it's OK. But, when I create the web worker again, the app will breakdown.

To reproduce

A vue component

<script setup>
import {ref} from "vue";

const num = ref(0)
let worker = undefined
function startWorker() {
    if (worker===undefined) {
        worker = new Worker('./worker.js')
        worker.onmessage = function(event){
            num.value = event.data;
        };
    }
}
function terminateWorker () {
    if (worker !== undefined) {
        worker.terminate()
    }
    worker = undefined
}
</script>

<template>
  <v-btn @click="startWorker">
          start worker
   </v-btn>
      <v-btn @click="terminateWorker">
          end worker
      </v-btn>
      <div>
          {{num}}
      </div>
</template>

<style scoped>

</style>

The worker.js

const ort = require("onnxruntime-node");
const fs = require("fs");
var i = 0;

function timedCount() {
  i = i + 1;
  postMessage(i);
  setTimeout("timedCount()",500);
}

timedCount();

ort.InferenceSession.create(fs.readFileSync("someModel.onnx"), { executionProviders:  ['cuda',  'wasm', 'cpu'])

If I delete the last line, I can restart the worker for many times. If I add the last line, if I restart the web worker, the app will crash. I suspect that is because the inferenceSession may not be closed properly when the worker is terminated. However, I can not find any api to close the inferenceSession. Another finding is that the memory is not released after the web worker is terminated.

Urgency

No response

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

"onnxruntime-node": "^1.12.1",

Execution Provider

Other / Unknown

@MountainAndMorning MountainAndMorning added the platform:web issues related to ONNX Runtime web; typically submitted using template label Sep 24, 2022
@fs-eire
Copy link
Contributor

fs-eire commented Sep 26, 2022

I think it is because the cuda execution provider is not functioning properly. could you try removing 'cuda' from the list and see if it runs?

@fs-eire
Copy link
Contributor

fs-eire commented Sep 26, 2022

I use the onnxruntime-node in the electron app with web worker. When I first create the web worker, it's OK. But, when I create the web worker again, the app will breakdown.

If you use onnxruntime-node in an electron app, the code should be running in the backend (ie. worker threads in Node), not in the frontend (web worker in Chromium).

@MountainAndMorning
Copy link
Author

Thanks for your help. The problem still exist after I remove the cuda backend. I have move the code to the main process. However, I still have a question. Is there any function to close the InferenceSession.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
platform:web issues related to ONNX Runtime web; typically submitted using template
Projects
None yet
Development

No branches or pull requests

2 participants