Skip to content

Commit c88c04a

Browse files
committed
changed mind again on letting threads finish in the background.
1 parent a4c9b9f commit c88c04a

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

crates/store/re_video/src/decode/ffmpeg.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -241,25 +241,27 @@ impl Drop for FfmpegProcessAndListener {
241241
// This should wake up the listen thread if it is sleeping, but that may take a while.
242242
self.ffmpeg.kill().ok();
243243

244-
// Wait for both threads to shut down.
245-
// Since we killed `on_output` this is not strictly necessary as the threads should come down eventually.
246-
// However, we'd like to avoid getting into a situation where repeated stream reset causes threads to accumulate.
247-
// With the above measures, this was found to be fast & reliable, but if stalls may show up here again,
248-
// we may decide to skip the below steps.
249-
// (DO NOT remove this as workaround for a stuck program! While this MAY be slow, it is NOT supposed to hang which indicates a bug in the shutdown logic!)
250-
{
251-
re_tracing::profile_scope!("shutdown write thread");
252-
if let Some(write_thread) = self.write_thread.take() {
253-
if write_thread.join().is_err() {
254-
re_log::error!("Failed to join ffmpeg listener thread.");
244+
// Unfortunately, even with the above measures, it can still happen that the listen threads take occasionally 100ms and more to shut down.
245+
// (very much depending on the system & OS, typical times may be low with large outliers)
246+
// It is crucial that the threads come down eventually and rather timely so to avoid leaking resources.
247+
// However, in order to avoid stalls, we'll let them finish in parallel.
248+
//
249+
// Since we disconnected the `on_output` callback from them, they won't influence any new instances.
250+
if false {
251+
{
252+
re_tracing::profile_scope!("shutdown write thread");
253+
if let Some(write_thread) = self.write_thread.take() {
254+
if write_thread.join().is_err() {
255+
re_log::error!("Failed to join ffmpeg listener thread.");
256+
}
255257
}
256258
}
257-
}
258-
{
259-
re_tracing::profile_scope!("shutdown listen thread");
260-
if let Some(listen_thread) = self.listen_thread.take() {
261-
if listen_thread.join().is_err() {
262-
re_log::error!("Failed to join ffmpeg listener thread.");
259+
{
260+
re_tracing::profile_scope!("shutdown listen thread");
261+
if let Some(listen_thread) = self.listen_thread.take() {
262+
if listen_thread.join().is_err() {
263+
re_log::error!("Failed to join ffmpeg listener thread.");
264+
}
263265
}
264266
}
265267
}

0 commit comments

Comments
 (0)