Repository navigation
fix(utvio): tear down GL on the writer thread; skip exit handlers on Linux (OpenRV ports) - #174
Merged
Merged
Conversation
…cky Linux 9 (OpenRV #1249) ### SG-42890: Fix BADACCESS X error when running RVIO commands on Rocky Linux 9 ### Summarize your change. - [X] Make the writer thread call MovieRV::uninit instead of the main thread - [X] Replace dummyDev raw pointer with an FBOVideoDevice unique_ptr ### Describe the reason for the change. AcademySoftwareFoundation/OpenRV#310 added `MovieRV::uninit` in the main function of RVIO to fix a GL error on exit on Rocky Linux 9. However, in a more recent version of the Rocky Linux 9, we are now getting a BADACCESS X error when running RVIO commands from the command line. An alert panel is also being displayed when submitting an image sequence through Screening Room after each step. This was caused by the main thread trying to access the OpenGL rendering context used by the writer thread when calling `MovieRV::uninit` at the end of the main function. It seems that the initial GL error was actually caused by the FBOVideoDevice raw pointer created as a dummy video device at the beginning of the main RVIO function by the main thread to avoid a segmentation fault. This raw pointer was never deleted, and this was causing a GL error when the `GLSyncObjectARBSync` destructor was called at the end of the program. Replacing the raw pointer with a unique_ptr fixed the leaking pointer that was the root cause of the GL error. `MovieRV::uninit` was not technically needed to fix the original GL error, but it's a good practice to keep it to make sure we uninit any FBOs that were allocated. The only difference is that it should have been called by the writer thread instead of the main thread since it is the one that actually created and used the FBOVideoDevice and the OpenGL rendering context during the execution of RVIO. ### Describe what you have tested and on which operating system. Submitting an image sequence through Screening Room was tested on Rocky Linux 9.6, Windows 11, and macOS 26.3. The following commands that were called during the submit process of Screening Room were also manually called from the command line to make sure no error remains: - `rvio movie.####.dpx -o /tmp/thumb.#.jpg` - `rvio movie.####.dpx -o /tmp/out.mov` - `rvio movie.####.dpx -resize 240 132 -outres 1200 132 -o /tmp/filmstrip.jpg` --------- Signed-off-by: Éloïse Brosseau <eloise.brosseau@autodesk.com> (cherry picked from commit 9fb070b) UTV: utvio no longer has the OSMesa path, so only the FBOVideoDevice change applies. The finalize also runs on the Windows ThreadedMovie path (upstream changed only the pthread one), and it deletes the PBO pools' buffers from #145 too, since that needs the writer thread's context as well. Signed-off-by: Michael Oliver <mcoliver@gmail.com>
…ux 9 (part 2) (OpenRV #1279) ### fix: SG-42890: Fix SIGSEGV error when running RVIO commands on Rocky Linux 9 (part 2) ### Linked issues NA ### Summarize your change. Fix an `rvio` SIGSEGV that fires at shutdown on Linux with the NVIDIA proprietary GL driver. Conversions complete successfully — the output `.mov` is written intact — but the process then exits with a segfault, which produces a crash dump and a non-zero exit code that breaks RV/CI/render-farm pipelines. Symptoms: - All frames are rendered and the output file is fully written. - The process then segfaults after `main()` returns. - Crashpad-symbolicated minidump shows the crashing thread's `rip` in an unmapped region with no usable call stack (only `stack scanning` frames in `libc.so.6`). The crash address looks like garbage because the page is already gone by the time the dump is written. Constant register signatures across ASLR-randomized runs (`rax=0x6e`, `r14=0x1e8480`, `r15=0xfffffffffffffb28`) confirmed the crash always lands at the same instruction. ### Root cause Captured under `gdb` (where the offending library is still mapped at the instant of the SIGSEGV), the crashing thread is an NVIDIA driver background worker: ``` Thread N "RVIO Main" received signal SIGSEGV 0x00007fffcd9f59ec in ?? () from /lib64/libnvidia-glcore.so.595.58.03 #0 libnvidia-glcore.so.595.58.03 #1 libnvidia-glcore.so.595.58.03 #2 libnvidia-glcore.so.595.58.03 #3 start_thread () from libc.so.6 #4 clone3 () from libc.so.6 ``` …while the main thread is mid-teardown: ``` #0 _dl_close_worker (...) at dl-close.c:769 #1 _dl_close #2 __GI__dl_catch_exception #5 dlclose@GLIBC_2.2.5 () #6 __glXMappingTeardown () from libGLX.so.0 #7 __glXFini () from libGLX.so.0 #8 _dl_fini () at dl-fini.c:148 #9 __run_exit_handlers () from libc.so.6 #10 exit () from libc.so.6 ``` This is the well-known **libglvnd ↔ NVIDIA driver shutdown race**: 1. `main()` returns. 2. libc's `exit()` runs `__run_exit_handlers` → `_dl_fini`. 3. `_dl_fini` invokes `libGLX.so.0`'s ELF destructor `__glXFini`, which `dlclose`s the NVIDIA GLX vendor (`libGLX_nvidia.so.0`) and transitively unmaps `libnvidia-glcore.so`. 4. NVIDIA's proprietary driver maintains its own internal helper threads. They are **not** joined by libglvnd's teardown — NVIDIA's blob has no such hook. The threads are still running when `dlclose` finishes. 5. The kernel unmaps `libnvidia-glcore.so`'s code pages out from under one of those running threads → next instruction fetch hits unmapped memory → SIGSEGV. The thread is named `"RVIO Main"` only because Linux child threads inherit their parent's `prctl(PR_SET_NAME)` value (set by `TwkUtil::setThreadName`). It is NOT the application's main thread. By the time crashpad's signal handler finishes serializing the minidump, `dlclose` has fully completed and the page is no longer in `/proc/self/maps`, which is why the dump appeared to crash "nowhere." ### Solution `src/bin/imgtools/rvio/main.cpp`: on Linux, replace the final `return 0;` in `utf8Main` with `std::_Exit(0);` — but only after all of rvio's legitimate shutdown has already run (`MovieRV::uninit`, `TwkMovie::GenericIO::shutdown`, `TwkFB::GenericIO::shutdown`, `TwkFB::ThreadPool::shutdown`). `std::_Exit` is the POSIX "skip atexit / `_dl_fini` and terminate now" primitive. It hands control directly to the kernel, which reaps memory, file descriptors, and threads — including NVIDIA's straggler threads — atomically, with no opportunity for the unload race. Nothing in our shutdown is left undone: - The output movie has already been finalized and `close`d by the writer before `utf8Main` reaches this point. - All Open RV-owned plugins have been shut down explicitly above the `_Exit` call. Windows and macOS still go through `return 0;` because they don't use libglvnd and don't exhibit this race. The change is `#ifdef PLATFORM_LINUX` guarded. Signed-off-by: Bernard Laberge <bernard.laberge@autodesk.com> (cherry picked from commit 6219ece) Signed-off-by: Michael Oliver <mcoliver@gmail.com> UTV: flush stdout, stderr and C stdio before _Exit, which skips that. Matters for utvio -v output redirected to a log.
mcoliver
force-pushed
the
port/openrv-utvio-teardown
branch
from
October 26, 2026 20:12
738bdd4 to
75badc4
Compare
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports two upstream utvio shutdown fixes listed in #166. Both are cherry-picked with
-x, and the original authors are kept.9fb070b (OpenRV #1249), Éloïse Brosseau
utvio renders on the ThreadedMovie writer thread, and the GL context is current there. At the end of the run the main thread called
MovieRV::uninit(), which makes that context current on the main thread:BadAccess. This is the upstream Rocky 9 failure.Changes:
ThreadedMovietakes a finalize function. It runs on the writer thread after the last frame.FBOVideoDeviceis now aunique_ptr.UTV adaptations:
TwkGLF::DeletePBOPoolBuffers()from fix(utvio): delete PBOs before driver shutdown at exit #145. That needs the same context, so it moves to the writer thread too. The PBOs are only used for uploads; readback isglReadPixelsinto CPU memory followed byglFinish, so nothing reads the buffers after the last frame.6219ece (OpenRV #1279), Bernard Laberge
On Linux, utvio calls
std::_Exit(0)after its own shutdown. That skips_dl_fini, where libglvnd'sdlcloseof the NVIDIA driver races the driver's helper threads and segfaults after the output has been written.UTV adaptation: flush
std::cout,std::cerrand C stdio first, because_Exitskips that and redirected-voutput would be lost.Testing
utvio in.mov -o out.movandutvio seq.#.exr -o out.#.jpgexit 0 on macOSBadAccess(Jim's dev-build pass)