getnamo / NodeJs-Unreal

Embed node.js as an Unreal Engine plugin.
MIT License
239 stars 34 forks source link

NodeJS processes hanging after application force close #57

Open mightyt73 opened 1 year ago

mightyt73 commented 1 year ago

Hello! I am having an issue with a packaged Steam application where I use NodeJs-Unreal. When a user closes the application incorrectly (alt-f4, force close, task manager, etc) it seems the currently running NodeJS processes are moved to the Background Processes in task manager. Steam detects that these are still part of the game execution and causes the Steam client to continue to say that the game is running.

When the user clicks my 'Exit' button, I use a script to kill all the NodeJS processes related to the application so this issue does not occur then.

I don't know if this is an issue or a feature, but it would be nice to be able for those processes to close automatically somehow. I am not super familiar with all of it so my suggestions are probably little value, but a timeout of some sort, or a way to detect that the main process force closed. Or maybe I am doing something incorrectly.

Thank you for all your work so far this code has been great to use!

getnamo commented 1 year ago

A timeout seems like a reasonable way to go. We can have a heartbeat from unreal e.g. every 10-30sec and if it doesn't receive it, exit the process.

Likely can be modified in the nodewrapper.js https://github.com/getnamo/NodeJs-Unreal/blob/master/Content/Scripts/nodeWrapper.js and an event listener with echo callback on runmainscript https://github.com/getnamo/NodeJs-Unreal/blob/master/Source/CommandLine/Private/NodeCmd.cpp#LL139C1, if echo not received within timeout interval, call gracefulexit.

I probably won't have time in the near term to add this, but this should be enough info for anyone to make a patch and open a pull request for the feature; I'll merge it then.

Cool to hear about an actual use case of the plugin in the wild, wishing the best for your project.

mightyt73 commented 1 year ago

I will try my best at it! Thank you so much for the direction.