You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Thanks for tackling the stop latency. I recommend addressing these before merging:
Missed shutdown notifications (high priority).shutdown_ and offset_shutdown are changed without holding shutdown_mut_, while the condition-variable predicates use that mutex. A notifier can set the flag and call notify_all() after the waiter reads false but before it enters the wait. The offset thread can then sleep for the full five-second interval. I reproduced this scheduling pattern in a standalone C++ harness. Update the predicate state under the same mutex, then notify, including both the normal and exception paths.
The unreachable-stream stop hang is not fully resolved.close_stream() in liblsl v1.18.0.b3 stops the data receiver; it does not cancel the separate metadata receiver. record_from_streaminfo() still calls in->info() with its default infinite timeout, including after an interrupted open_stream(). With an unreachable metadata endpoint, Stop can therefore still block indefinitely. Also, the existing try_join_once() calls blocking std::thread::join(), so the reduced max_join_wait does not bound this wait. Please use bounded metadata waits that observe shutdown and explicitly handle stopping during subscription/header retrieval.
Validation does not cover these guarantees yet. The new integration script is not called by the checked-in CI workflow. It verifies only the EEG footer, not the silent marker stream's footer, and permits 1.5 seconds despite documenting a 500 ms limit. Please run it in CI, check both footers and process exit status, and add stop-during-connect/metadata and repeated shutdown cases.
Review scope: source inspection against the PR head and liblsl v1.18.0.b3, plus the isolated condition-variable reproduction; I did not run the full integration script.
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. Becauserecord_offsets()used an uninterruptible 5-second sleep (std::this_thread::sleep_for(offset_interval)) andboundary_threadjoined 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
std::condition_variable shutdown_cv_inrecordingand replacedstd::this_thread::sleep_for/sleep_untilacrossrecord_offsets(),record_boundaries(), andtyped_transfer_loop()with condition variable waits. When shutdown is triggered, all worker threads wake up in < 1 ms.lsl::stream_inletinstances and invokein->close_stream()on shutdown to abort any blocking TCP socket calls or unreachable remote network routes immediately.in->pull_sample()timeout from 4.0s to 0.1s so silent or late-starting streams checkshutdown_rapidly.scripts/test_recording_teardown.pyto verify thatLabRecorderCLIstops in < 0.5s and produces fully valid, uncorrupted XDF files with intact footers.Verification
.xdfparses cleanly withpyxdf.