Synchronize cloud telemetry lifecycle to fix shared-state races#1019
Open
jnunemaker wants to merge 2 commits into
Open
Synchronize cloud telemetry lifecycle to fix shared-state races#1019jnunemaker wants to merge 2 commits into
jnunemaker wants to merge 2 commits into
Conversation
record, post_to_pool, and post_to_cloud read @metric_storage/@pool/@Timer while restart (on fork) and stop (on a telemetry-shutdown header) reassign or tear them down with no synchronization. Concurrent fork detection could double up restarts, leaking a pool+timer with live threads, and readers could observe an inconsistent storage/pool/timer trio or write into a swapped-out storage. Guard the lifecycle (start/stop/restart) with a mutex via internal start!/stop!/ restart! variants, use double-checked locking in detect_forking so exactly one thread restarts while keeping the hot record path lock-free, and snapshot the swapped ivars into locals in the worker paths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
e8566fe to
283b3bd
Compare
record, post_to_pool, and post_to_cloud read @metric_storage/@pool/@Timer while restart (on fork) and stop (on a telemetry-shutdown header) reassign or tear them down with no synchronization. Concurrent fork detection could double up restarts, leaking a pool+timer with live threads. Guard the lifecycle (start/stop/restart) with a mutex via internal start!/stop!/ restart! variants, and use double-checked locking in detect_forking so exactly one thread restarts while keeping the hot record path lock-free. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
283b3bd to
71b80c4
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Flipper::Cloud::Telemetryreassigned and tore down shared state (@metric_storage/@pool/@timer) with no synchronization, so concurrent fork detection could double up restarts (leaking a pool and timer with live threads) and readers could observe an inconsistent storage/pool/timer trio. This guards the lifecycle (start/stop/restart) with a mutex via internalstart!/stop!/restart!variants and uses double-checked locking indetect_forkingso exactly one thread restarts on fork. The hotrecordpath stays lock-free (it only touches the mutex when a fork is actually detected), and the worker paths snapshot the swapped ivars into locals. Adds specs proving exactly one restart under concurrent fork detection and that records aren't lost while a fork restart is in progress.🤖 Generated with Claude Code