Skip to content

fix(linux): disable GStreamer's segfault trap so plugin loads can't kill the JVM - #268

Closed
muthuraj57 wants to merge 1 commit into
kdroidFilter:masterfrom
muthuraj57:linux-gst-segtrap
Closed

muthuraj57 wants to merge 1 commit into
kdroidFilter:masterfrom
muthuraj57:linux-gst-segtrap

Conversation

@muthuraj57

Copy link
Copy Markdown

Problem

On Linux the app can exit with code 255 while a video opens, with this in the log:

ERROR: Caught a segmentation fault while loading plugin file:
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstnvcodec.so

GStreamer's segfault trap is on by default. While GStreamer loads a plugin it installs its own SIGSEGV handler. The JVM raises SIGSEGV on purpose (stack banging, implicit null checks, safepoint polls) and handles it itself. If one of those lands during a plugin load, GStreamer's handler catches it and calls exit(-1), which ends the whole process. Slow plugins make this likely: the NVIDIA decoder plugin takes about 1.4 s to load, so on machines with an NVIDIA GPU the first video often killed the app.

Fix

gst_init_func (run once through pthread_once in nvp_create) now calls gst_segtrap_set_enabled(FALSE) before gst_init(). A plugin that really crashes then crashes the JVM, which writes its own crash report.

Verification

I used a standalone JNI harness on Ubuntu x86-64 with an NVIDIA GPU. It loads libNativeVideoPlayer.so, calls nCreatePlayer (which runs gst_init), then loads libgstnvcodec.so while a Java thread keeps overflowing its stack.

  • Before the fix, 3 of 3 runs: the trap stays on after the player is created, and the process exits with 255 and the message above.
  • With the fix, 3 of 3 runs: the trap is off after the player is created, the plugin loads in about 1.5 s, and the process exits normally.

…ill the JVM

While GStreamer loads a plugin it installs its own SIGSEGV handler. The JVM raises SIGSEGV on purpose
(stack banging, implicit null checks, safepoint polls) and handles it itself; if one lands during a plugin
load, GStreamer's handler prints "Caught a segmentation fault while loading plugin file" and calls exit(-1),
so the app dies with exit code 255. Call gst_segtrap_set_enabled(FALSE) before gst_init().
@kdroidFilter

Copy link
Copy Markdown
Owner

Thank you! The code of this library now lives in the Nucleus repository (the media modules), see the README and the migration guide. This is still relevant, so it continues in NucleusFramework/Nucleus#995. Closing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants