lovell / lovell/sharp

Electron: Segmentation fault / SIGTRAP in g_object_ref during OpenInput on Ubuntu 24.04

Open
#4,522 18 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
32.7k
Forks
1.4k
Avg merge
1d 14h
Merged PRs (30d)
5

Description

Environment

  • OS: Ubuntu 24.04.4 LTS (Kernel 6.17.0-20-generic)
  • GLib: 2.80.0-6ubuntu3.8
  • GObject: libgobject-2.0
  • Node.js: v24.14.1
  • sharp: 0.34.5 (bundled in Electron app, @img/sharp-linux-x64)
  • Electron: 41.2.0
  • Runtime: Wayland (GNOME), AMD Cezanne APU

Description

We're experiencing random crashes in an Electron app that uses sharp for image processing. The crash occurs in a
libuv-worker thread when sharp::OpenInput() calls g_object_ref(), which triggers a GLib-GObject assertion
failure (G_IS_OBJECT (object)), resulting in SIGTRAP / Trace/breakpoint trap.

The crash is intermittent — sometimes the app starts fine, sometimes it crashes 2-3 times before succeeding. It
appears to be a race condition in multi-threaded usage.

Stack Trace (from gdb)

Thread 44 "libuv-worker" received signal SIGTRAP, Trace/breakpoint trap.
#0 0x00007ffff7eac671 in g_logv () at libglib-2.0.so.0
#1 0x00007ffff7eac923 in g_log () at libglib-2.0.so.0
#2 0x00007ffff79be9bc in g_object_ref () at libgobject-2.0.so.0
#3 0x00007fff5796d6e5 in sharp::OpenInput(sharp::InputDescriptor*) () at sharp-linux-x64.node
#4 0x00007fff5796f405 in ??? () at sharp-linux-x64.node
#5 0x00007fff57966eac in ??? () at sharp-linux-x64.node
#6 0x0000555558301537 in node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*)#1}::__invoke(uv_work_s*) ()

Workaround

Setting UV_THREADPOOL_SIZE=1 eliminates the crash completely, suggesting a thread-safety issue in libvips/GLib when
multiple worker threads call g_object_ref concurrently.

UV_THREADPOOL_SIZE=1 open-orpheus  # No crash
UV_THREADPOOL_SIZE=4 open-orpheus  # Random crash (default)

Additional Notes

- This issue was not reproducible in VMware Workstation with the same OS/software versions, but the same GLib
assertion failures were observed without the actual crash.
- Downgrading Electron from v41 to v40.8.5 reduced crash frequency but did not eliminate it.
- The issue seems specific to GLib 2.80 on Ubuntu 24.04.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the crash in the Electron app with the reported Ubuntu, Electron, Node.js, and sharp versions, comparing UV_THREADPOOL_SIZE=1 and 4. Read the sharp::OpenInput() stack-trace entry and the surrounding libuv-worker calls. Done means the intermittent GLib assertion and SIGTRAP no longer occur with the default worker pool while image processing still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, javascript, node.js
Domain
desktop, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.