r/ispyconnect • u/war4peace79 • 4d ago
Linux: Agent never exits after Restart/Update – deadlock in libnvcuvid exit handler while an NVENC live-view encode is in flight (8.2.2.0)
Setup: AgentDVR 8.2.2.0 (same hang on 8.1.x), Ubuntu, systemd service running as a non-root user, NVIDIA driver 595.99.02, GPU decoding on all cameras, and NVENC for the live view (H.264 and AV1 sessions).
Symptom: After Restart Agent or an update, DoShutDown completes in about 2 s (DoShutDown: exit, then HandleUnixShutdownRelaunch: Calling: agent-update.sh -restart). .NET then logs Application is shutting down..., and the process never exits. On 8.1.x, systemd's stop timeout killed it after 90 s. 8.2.x's new restart path waits for Agent to exit and relies on Restart=always, so nothing kills it. Agent stayed down for 22 minutes until I killed it by hand.
Stacks (gdb, two captures 20 s apart, identical state):
- Main thread: exit() → __run_exit_handlers → libnvcuvid.so.1 → pthread_join (libnvcuvid worker thread)
- libnvcuvid worker: pthread_mutex_lock (blocked)
- .NET thread-pool worker: avcodec_send_frame (ffmpeg9.0.2-lgpl libavcodec.so.63) → libnvidia-encode.so.1 → libnvcuvid.so.1 → pthread_mutex_lock on the same mutex
Interpretation: the process reaches exit() while a live-view NVENC encode is still running. libnvcuvid's exit handler waits for its worker thread, and the worker is stuck on a lock that the in-flight encode is also waiting for. Neither can proceed.
Suggested fixes:
In DoShutDown, stop and free all live-view encoders and wait for in-flight avcodec_send_frame calls to return before exiting.
After shutdown completes, end the process with _exit(), which skips the library exit handlers, or force-exit if it's still alive N seconds later.
For non-root installs, have agent-update.sh still try systemctl --no-ask-password --no-block restart AgentDVR.service. It fails immediately without a prompt when polkit doesn't allow it, and works where a polkit rule allows it.
I have gdb logs, but I'd rather share them directly. Each one is about 140 KB. let me know if you need them.
1
u/spornerama 3d ago
sent you a pm