Fix (high): serialize runtime creation under the per-app operation lock - #799
Closed
Rigidity wants to merge 1 commit into
Closed
Fix (high): serialize runtime creation under the per-app operation lock#799Rigidity wants to merge 1 commit into
Rigidity wants to merge 1 commit into
Conversation
create_runtime resolved the app (which acquires the per-app operation
lock) and then immediately dropped the guard via into_app() before
rotating storage, writing the runtime record, and creating the webview.
Two concurrent starts for the same app could therefore both see it as
stopped and both create a runtime, and because the runtime is recorded
before its webview exists, a concurrent resolve_app could return Running
for an app whose webview lookup fails ("phantom" runtime).
Keep the operation guard held across the whole create/rotate/webview
sequence (new into_app_and_guard). A second concurrent start now blocks in
resolve_app until the first finishes and then observes the completed
runtime instead of creating a duplicate.
Contributor
|
Fixed: 817e902 |
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.
Severity: High (H7)
Problem
create_runtimeresolved the app viaresolve_app— which acquires the per-app operation lock and returns it insideResolvedStoppedApp— and then immediately dropped that guard withstopped.into_app()before rotating storage, callingwrite_runtime, and creating the child webview.Consequences:
apps_start_user_appcalls for the same app can both observe it as stopped and both proceed, producing duplicate runtimes (both maps get overwritten with no "already exists" check).write_runtimerecords a "running" runtime before the webview exists, so a concurrentresolve_appreturnsRunningfor an app whose webview lookup then fails (a "phantom" runtime).Fix
Add
ResolvedStoppedApp::into_app_and_guard()and keep the operation guard held through the entire create/rotate/webview sequence increate_runtime_for_app(passed as anOption<OwnedMutexGuard<()>>). A second concurrent start now blocks inresolve_appuntil the first finishes and then observes the completed runtime instead of creating a duplicate. Internal/origin-cleanup starts that don't go throughresolve_apppassNone.Files
crates/sage-apps/src/runtime/start.rscrates/sage-apps/src/types/app/user_apps.rsFollow-up (not in this PR)
The related clear-data race the review notes —
resolve_stopped_appreleases the op lock between its close-and-retry attempts, so a concurrent start can interleave withapps_clear_runtime_browsing_dataafter rotation — is a separate change to the retry/close protocol and is left for a focused follow-up.No local build (per request); relying on CI.
Note
Medium Risk
Touches core app runtime lifecycle and concurrency; scope is narrow and behavior-preserving aside from fixing races, but incorrect locking could still affect startup reliability.
Overview
Serializes user-app runtime startup by keeping the per-app operation mutex from
resolve_appuntil the webview is created, instead of dropping it when extracting the stopped app.create_runtimenow usesinto_app_and_guard()and passes that guard intocreate_runtime_for_appas an optional_op_guardheld for the full rotate →write_runtime→ child webview path. Concurrent starts for the same app block on the lock; the second caller should see an already-running runtime rather than spawning duplicates or a phantom runtime recorded before the webview exists.Internal paths that skip
resolve_app(e.g. origin cleanup) passNonefor the guard.Reviewed by Cursor Bugbot for commit b288068. Bugbot is set up for automated code reviews on this repo. Configure here.