Skip to content

fix(ndi): wake the send thread on shutdown so the consumer can be destroyed - #1855

Open
FiLORUX wants to merge 1 commit into
CasparCG:masterfrom
FiLORUX:fix/ndi-consumer-shutdown-hang
Open

FiLORUX wants to merge 1 commit into
CasparCG:masterfrom
FiLORUX:fix/ndi-consumer-shutdown-hang

Conversation

@FiLORUX

@FiLORUX FiLORUX commented Nov 25, 2026 •

Copy link
Copy Markdown

Problem

A channel with an NDI consumer hangs on shutdown. ~newtek_ndi_consumer() calls send_thread.interrupt() and then join(), but the send thread spends its time in worker_cond_.wait(...) on a std::condition_variable. That is not a boost::thread interruption point, so the interrupt never wakes it. Once the channel stops delivering frames (as it does while shutting down), nothing notifies the condition variable again and join() waits forever.

Seen on a Windows playout server (2.5.0, six channels, NDI on one of them): every KILL stopped at video_channel[6] Uninitializing and the process had to be terminated. DeckLink on the same channel never got to Scheduled playback has stopped, because the NDI consumer (index 900) is torn down before it.

Fix

The destructor sets a stopping_ flag under buffer_mutex_ and calls notify_all() before the existing interrupt()/join(). Both waits in the send thread include the flag in their predicate and return when it is set. Behaviour while running is unchanged.

Testing

Applied to the same code on 2.5.0-stable and deployed on that server: KILL now completes in about 5 s, with ndi_consumer[6|MV] Uninitialized, the screen and DeckLink consumers on that channel uninitialised in turn, and Successfully shutdown CasparCG Server. This branch also builds on Windows and on Linux (system dependencies) with the repository's workflows.

…troyed

The send thread waits on a std::condition_variable, which is not a
boost::thread interruption point, so interrupt() in the destructor never
woke it. Once the channel stopped delivering frames, join() waited
forever and the server could not shut down. The destructor now sets a
stop flag under the buffer mutex and notifies the thread, and both
waits return on it.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The NDI consumer now signals the send thread during destruction. Both worker waits check the stop request and return instead of continuing to wait or process another frame.

Changes: NDI consumer shutdown

Layer / File(s) Summary
Worker shutdown signaling
src/modules/newtek/consumer/newtek_ndi_consumer.cpp
The destructor sets the stop request and notifies the worker condition variable before interrupting and joining the send thread. The initial buffering wait and frame-availability wait now return when stopping is requested.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: julusian, niklaspandersson

Merge Risk: Minimal · up to ca327

This change wakes the NDI send thread during shutdown so the consumer can be destroyed instead of hanging. Behavior while running is unchanged, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the NDI consumer's send thread is woken on shutdown so the consumer can be destroyed. The raw summary confirms the destructor sets a stop flag, notifies the worker con…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: the NDI consumer's send thread is woken on shutdown so the consumer can be destroyed. The raw summary confirms the destructor sets a stop flag, notifies the worker condition variable, and both waits return when stopping is requested. The title follows the conventional commit style and is concise. It does not describe the mutex or predicate details, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3296333a-4bd3-47be-8f03-c27016901091
Commits

Reviewing files that changed from the base of the PR and between 31b6ef7 and ca3276d.

Files selected for processing: 1

  • src/modules/newtek/consumer/newtek_ndi_consumer.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

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.

1 participant