The wrong unwinder: a Flutter Linux crash inside libmpv's Lua
The report was almost useless: “it was closed when it was downloading a video.”
No error dialog. No red screen. No Dart exception in the log. The app simply disappeared while a chat with a video was open, and the console ended by reporting that it had lost the connection to the running app. If you have debugged a mobile app long enough, that message usually means the process died below Dart, where Flutter cannot catch it.
This is the story of that crash. It is a good one because nothing in the app pointed at the cause. The app was not leaking memory, the video was not corrupt, and the download was fine. The failure lived in a C library loaded by the video player, and the fix was a single change to the order in which two shared libraries are loaded.
If you use the Linux desktop build of Folcadi, the short version is: video playback is stable in builds made after this fix, and older builds keep the old link order. If you are a developer, the second half of this post is the debugging path and the exact change.
What the crash looked like
The user was in a normal chat. A video message was downloading. The window closed.
There was no partial render, no graphics glitch, and no warning. From the outside it looked like the app had been killed. From the inside, the process had received a segmentation fault, which is the operating system’s way of stopping a program that touched memory it should not have.
The important detail is what was absent. A Flutter error has a stack trace with Dart frames and usually a readable message. This had neither. That absence is the first split in the decision tree: either the Dart isolate crashed in a way that bypassed the handler, or a native library underneath it crashed the whole process.
Here it was the second one.
The clue that changed the investigation
The desktop keeps core dumps, the frozen memory snapshots a crashing process can leave behind. Three were present: two from the installed release build, one from a debug build. All three had the same signal, and all three died on the same thread: the one the video player uses for a small Lua statistics script.
That thread is the whole story. It is not part of Folcadi. It belongs to the video player’s underlying media library, which loads a built-in Lua script for playback statistics. The crash was not in the chat UI, the download code, or the video file. It was inside a scripting engine the video player had started on its own.
The video was only the trigger. Opening a chat with a video, scrolling past one, or downloading one could wake that script.
Why a video player can take down the whole app
A desktop video player is not a sandbox. It is a large native library loaded into the same process as the app, with its own threads, its own scripting engine, and its own error handling.
Folcadi plays video on Linux through the system media library, because Flutter’s mobile video plugin has no Linux implementation. That library renders through the operating system’s media engine and loads Lua scripts for features like the playback stats overlay.
When one of those scripts hits a path the just-in-time compiler cannot translate, the scripting engine aborts that compiled path and throws an exception internally. That is normal. It happens during ordinary playback and is supposed to be caught a few frames later.
The exception never made it back. Instead, the unwinder — the part of the runtime that walks the call stack during an exception — was the wrong one, and the crash happened while trying to leave the failed script.
The fix: let the standard unwinder load first
The app’s Linux launcher now asks the system’s standard C unwinder to load before Flutter’s runtime library. That sounds like a build detail because it is one, but the effect is concrete: the scripting engine now finds the unwinder it expects, the internal exception is handled normally, and the video player no longer brings the process down.
The change is small enough to state plainly: the launcher declares the standard unwinder as its first shared-library dependency, then Flutter. Because of how the Linux dynamic linker resolves symbols, being first is what matters.
A new build is stable. An old build is not retroactively fixed, because the link order is baked into the binary at build time. If you installed a Linux bundle before this change, it still carries the old order and can still crash on video; updating to a newer build is the fix.
What changed for Linux users
If you use the Linux desktop app, the user-visible change is simple: videos and video messages no longer close the app on their own.
There is no new setting, no toggle, and no migration. The app behaves the same way; the difference is that a failure path inside the media library now completes instead of taking the window with it.
We also documented the constraint in the desktop notes, because the link order is the kind of thing a future cleanup can silently undo. If someone removes the dependency as “unused”, the crash comes back. The documentation says: do not reorder or drop it.
For developers
The debugging path matters more than the fix, because the fix is two lines of CMake.
Getting a real stack
The crash left core dumps, so the first job was to get symbols for the native libraries. On the test machine, coredumpctl listed three dumps, all SIGSEGV, all in the same thread. Symbolicating with debuginfod (which fetched debug info for LuaJIT and the media library) produced the actual stack:
lj_cf_package_require
→ lj_trace_err_info(LJ_TRERR_NYIBC) # JIT trace aborted
→ lj_err_throw
→ _Unwind_RaiseException # resolved to libflutter_linux_gtk.so
→ lj_err_unwind_dwarf → err_unwind # null deref, SIGSEGV
LJ_TRERR_NYIBC means the JIT hit a bytecode it does not compile. That is an ordinary trace abort. The surprise is the frame after it: _Unwind_RaiseException resolved to libflutter_linux_gtk.so, not to the standard libgcc_s.so.1.
Two definitions, one global scope
The process contains two definitions of _Unwind_RaiseException: the standard one in libgcc_s.so.1, and one exported by libflutter_linux_gtk.so. The dynamic linker picks a definition by its position in the global symbol scope. Flutter was earlier, so LuaJIT’s call bound to Flutter’s copy.
Flutter’s copy does not know how to unwind LuaJIT’s foreign exception class (uexclass = "LUAJIT2\x02"). The unwind walks with the wrong assumptions and dereferences a bad pointer, which is the SIGSEGV in lj_err_unwind_dwarf.
LD_DEBUG=bindings makes the binding explicit:
binding file libluajit-5.1.so.2 to libflutter_linux_gtk.so:
normal symbol `_Unwind_RaiseException'
This also explains why a plain media player on the same machine is stable: no Flutter library is loaded, so LuaJIT binds to libgcc_s and the trace abort unwinds normally.
The fix and why --no-as-needed is required
The runner now links gcc_s before flutter, and forces the dependency to survive the link:
target_link_options(${BINARY_NAME} PRIVATE "LINKER:--no-as-needed")
target_link_libraries(${BINARY_NAME} PRIVATE gcc_s)
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
--no-as-needed matters because the launcher references no libgcc symbol directly. Without it, the linker sees the dependency as unused and drops it, and the ordering trick disappears. With it, libgcc_s.so.1 becomes the first NEEDED entry, so LuaJIT resolves the unwinder to the standard implementation.
Verification
flutter build linux --debugand--releaseboth succeed.readelf -dlistslibgcc_s.so.1as the firstNEEDEDentry in both builds.LD_DEBUG=bindingsnow reportslibluajit-5.1.so.2 → /usr/lib/libgcc_s.so.1 : _Unwind_RaiseException.- A minimal reproducer confirms the mechanism independently: a plain LuaJIT
error()underlua_pcallexits cleanly; the same binary preloaded withlibflutter_linux_gtk.soexits with a segmentation fault; preloadinglibgcc_s.so.1first exits cleanly.
No Flutter or Dart tests were added. This is a native link-order property, not application behaviour, and the honest verification is the loader output plus the reproducer. The caveat is the same one that matters to users: binaries built before the change keep the old order.
What I would take to another project
Three lessons generalize beyond Flutter and Lua:
- A silent process death is a native problem until proven otherwise. No Dart stack, no Flutter error widget, just a closed window: start at the core dump, not at the Dart code.
- Read the thread name before the stack.
lua/statstold us which subsystem to look at before symbolication finished. Faulting-thread names are cheap, high-signal evidence. - Global symbol scope is load order. Two libraries can export the same symbol, and the earlier one wins. If a native dependency starts throwing across an ABI boundary, check which implementation the linker actually bound, not which one you assumed was there.
The fix is two lines and a comment. Finding it required accepting that the app was not the thing that crashed.
Have you ever chased a “the app just closed” bug that turned out to live in a dependency’s dependency? What finally pointed you at it?