Skip to content

frontend: Use the reentrant localtime in timestamps and filenames - #418

Merged
zackees merged 2 commits into
masterfrom
fix/132-localtime-r
Oct 13, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/132-localtime-r

Conversation

@zackees

@zackees zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Closes #132.

CurrentTimeString() (frontend/obs-main.cpp) stamps every blog() line, and blog() runs on the audio, video, capture and UI threads at once. localtime() returns one static buffer shared by all of them, so concurrent log lines could swap or corrupt timestamps (TSan: data race on libc _tmbuf).

  • RED: ci/test_localtime.py (run by ./lint) bans plain localtime(/std::localtime( under frontend/ and lists 4 sites. The race itself isn't deterministic to test; the call pattern is.
  • GREEN: all four use localtime_r, or localtime_s on Windows: CurrentTimeString, CurrentDateTimeString and GenerateTimeDateFilename (OBSApp.cpp), and buildCrashLogUploadContent (CrashHandler.cpp).

Not touched: os_generate_formatted_filename in libobs/util/platform.c has the same pattern, but that file is claimed under #262. I've flagged it there. obs-win-crash-handler.c runs once at crash time.

The frontend isn't compiled by the local gate, so this PR's full OBS builds are the compile check for both branches. The local gate passed and is stamped.

…EEN)

CurrentTimeString stamps every log line from the audio, video, capture
and UI threads, and localtime() shares one static buffer between them.
The other frontend callers move too: localtime_r, or localtime_s on
Windows.

Closes #132

Local-Gate: v1 tree=c6b21014861dd61d1d108f9466394e5f1e3631b7 secs=130 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791852596,"gate":"rust/all/fmt","host":"linux-x86_64","key":"0b777466bd39d4136d790559551d68767cb54da020eac8c3447fdb56af3d5748","lane":"lint","parents":["6670cc5130760ac38dc74df9480c8f48fc1d3cd3"],"secs":16,"stamp":"da52584d2cfcf98c0dad5efe9bb7d07a","tree":"c6b21014861dd61d1d108f9466394e5f1e3631b7","v":1,"via":"run"}
Ci-Attestation: {"at":1791852596,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"0b777466bd39d4136d790559551d68767cb54da020eac8c3447fdb56af3d5748","lane":"lint","parents":["6670cc5130760ac38dc74df9480c8f48fc1d3cd3"],"secs":16,"stamp":"8feb0f214c7b5e68ded72684b7ab5785","tree":"c6b21014861dd61d1d108f9466394e5f1e3631b7","v":1,"via":"run"}
Ci-Attestation: {"at":1791852596,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"e7ea5ac5f3680b5589986af5502f44b60352b526f4358dbb2b8a587f6294b38f","lane":"rust-test","parents":["6670cc5130760ac38dc74df9480c8f48fc1d3cd3"],"secs":52,"stamp":"e70b4345fd44cbf84ea1e07e6217dc09","tree":"c6b21014861dd61d1d108f9466394e5f1e3631b7","v":1,"via":"run"}
Ci-Attestation: {"at":1791852596,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"f081348bc641e683a558f77e302ee85442c7469ffb1361cb0724bd227aa3f953","lane":"tier2-linux","parents":["6670cc5130760ac38dc74df9480c8f48fc1d3cd3"],"secs":61,"stamp":"1bbf8ab0fcdde231955dc35edd52e1aa","tree":"c6b21014861dd61d1d108f9466394e5f1e3631b7","v":1,"via":"run"}
@zackees
zackees merged commit 37f9f77 into master Oct 13, 2026
23 checks passed
@zackees
zackees deleted the fix/132-localtime-r branch October 26, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

TSan: CurrentTimeString uses non-reentrant localtime() from every logging thread

1 participant