When stopping a recording, recording::~recording() executes synchronously on the Qt UI thread. Because record_offsets() used an uninterruptible 5-second sleep (std::this_thread::sleep_for(offset_interval)) and boundary_thread joined with a 15-second timeout, the Qt event loop blocked, causing Windows to mark the window as "(Not Responding)" for 5–15+ seconds. Forcefully terminating the application when frozen aborted before stream footers could be written, resulting in corrupted XDF footers and truncated files.
Solution
Interruptible Thread Teardown: Added a std::condition_variable shutdown_cv_ in recording and replaced std::this_thread::sleep_for / sleep_until across record_offsets(), record_boundaries(), and typed_transfer_loop() with condition variable waits. When shutdown is triggered, all worker threads wake up in < 1 ms.
Active Socket Teardown: Track active lsl::stream_inlet instances and invoke in->close_stream() on shutdown to abort any blocking TCP socket calls or unreachable remote network routes immediately.
Low-Latency First-Sample Check: Lowered the initial in->pull_sample() timeout from 4.0s to 0.1s so silent or late-starting streams check shutdown_ rapidly.
Automated Integration Test: Added scripts/test_recording_teardown.py to verify that LabRecorderCLI stops in < 0.5s and produces fully valid, uncorrupted XDF files with intact footers.
Verification
Tested on Windows and Ubuntu via GitHub Actions CI and local automated integration tests.
Confirmed teardown completes in ~0.5s and resulting .xdf parses cleanly with pyxdf.
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
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.
Problem
When stopping a recording, recording::~recording() executes synchronously on the Qt UI thread. Because record_offsets() used an uninterruptible 5-second sleep (std::this_thread::sleep_for(offset_interval)) and boundary_thread joined with a 15-second timeout, the Qt event loop blocked, causing Windows to mark the window as "(Not Responding)" for 5–15+ seconds. Forcefully terminating the application when frozen aborted before stream footers could be written, resulting in corrupted XDF footers and truncated files.
Solution
Verification