samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.67k stars 63 forks source link

Exporting PNG or JPG image prevents nodejs exit when gpu = enabled. #126

Open themrrobert opened 1 year ago

themrrobert commented 1 year ago

Problem:

Based on my [limited] understanding of node.js, my theory is that when gpu is enabled, the png/jpg exporter is leaving a thread open/un-reaped which is prevent node.js from exiting fully.

Worth noting, that toBuffer / get png / jpg work fine, and do not hang themselves. Everything works normally until you try and exit node/kill the script, and that's when it just refuses to exit. (The script stops executing and freezes/hangs, but node does not exit, and requires the entire terminal to be killed or task-manager force quit.)

Workaround:

Set canvas.gpu = false before executing export commands

Environment:

skia-canvas version: 1.0.1 Node 18.12.0 GPU: GTX Titan X nvidia driver version: 512.77 Windows 10 Pro - 10.0.19044 Build 19044 CPU i7-5960x - 64GB RAM

Important

/edit: The simplest test case exits gracefully, so there's another factor i'm trying to isolate, however what we do know is that it works fine with gpu = disabled OR if we just never export to png/jpg.

Other modules used

discord.js pqueue lots more. will try to narrow it down and update

mpaperno commented 1 year ago

FWIW, I can confirm this issue here. We must kill (SIGTERM) the node process (from inside the program code itself) to exit the application after using GPU rendering and toBuffer('png').