mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 20:26:05 -05:00
fix: stop the nph-zms command thread racing runStream on frame bookkeeping
checkCommandQueue runs processCommand on its own thread, which read `now` and frame_count and wrote last_frame_sent (CMD_PAUSE) and got_command while the streaming loop writes or reads them. ThreadSanitizer reports these as data races (zm_monitorstream.cpp processCommand and runStream's got_command read against the command thread, and checkCommandQueue's `now` read against EventStream::runStream). Make frame_count, last_frame_sent and got_command atomic, as #4939 did for the playback state, and have the command thread read the clock itself instead of the loop's `now`. The status reply's fps and delay are then measured against the current time rather than the start of the loop's last pass. Test: [races] case for the frame bookkeeping, for TSan builds. fixes #5230 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3d2e542bc
commit
22d02ce066
5 files changed
+89
-27
No files matched your search
+5
-2
@@ -126,9 +126,12 @@ void StreamBase::updateFrameRate(double fps) {
|
||||
void StreamBase::checkCommandQueue() {
|
||||
while (!zm_terminate) {
|
||||
// Update modified time of the socket .lock file so that we can tell which ones are stale.
|
||||
if (now - last_comm_update > Hours(1)) {
|
||||
// This is the command thread: read the clock here rather than the
|
||||
// streaming loop's `now`.
|
||||
TimePoint cmd_now = std::chrono::steady_clock::now();
|
||||
if (cmd_now - last_comm_update > Hours(1)) {
|
||||
touch(sock_path_lock);
|
||||
last_comm_update = now;
|
||||
last_comm_update = cmd_now;
|
||||
}
|
||||
|
||||
if (sd >= 0) {
|
||||
|
||||
Reference in new issue
Block a user