Skip to content

Bug 2054982 - Finer grained locking for RemoteSettingService#7474

Open
bendk wants to merge 1 commit into
mozilla:mainfrom
bendk:bdk/push-qyzkwrspulzl
Open

Bug 2054982 - Finer grained locking for RemoteSettingService#7474
bendk wants to merge 1 commit into
mozilla:mainfrom
bendk:bdk/push-qyzkwrspulzl

Conversation

@bendk

@bendk bendk commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Split up RemoteSettingServiceInner into multiple structs, each with their own Mutex and add a bit of policy around locking them. Right now this is just enforced by putting all the methods that lock them in one impl block.

The issue we're trying to avoid is having RemoteSettingService::sync block RemoteSettingService::make_client.

Also, start using viaduct::Client which should be possible now since all applications are using the new backend.

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

@bendk bendk requested a review from gruberb July 14, 2026 19:52

@gruberb gruberb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have to(please double check) combine creating the config and registering the client into one operation not to get out of sync. We can keep sync_client separate not to be blocking.

struct RemoteSettingsService {
    storage_dir: Utf8PathBuf,

    // Short-lived lock: configuration and client registration.
    state: Mutex<RemoteSettingsServiceState>,

    // Long-lived lock: held across the monitoring network request.
    sync_client: Mutex<RemoteSettingsServiceSyncClient>,

    telemetry: Mutex<RemoteSettingsTelemetryWrapper>,
}

struct RemoteSettingsServiceState {
    config: RemoteSettingsServiceConfig,
    clients: Vec<Weak<RemoteSettingsClient>>,
}

Comment on lines +88 to +96
let config = self.clone_config();
let client = Arc::new(RemoteSettingsClient::new(
inner.base_url.clone(),
inner.bucket_name.clone(),
config.base_url,
config.bucket_name,
collection_name.clone(),
inner.app_context.clone(),
config.app_context.clone(),
storage,
));
inner.clients.push(Arc::downgrade(&client));
self.push_client(Arc::downgrade(&client));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make_client() race with update_config() here? clone_config() releases the config lock before this client is added to clients. If update_config() runs between these calls, active_clients() won’t include the new client, but the service config will be replaced. The client can then be registered with the old config and never receive the update.

Could config access and client registration/update share one short-lived mutex-protected state? sync_client could remain separate, so this would not reintroduce the original network-blocking issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes it could indeed, nice catch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed your suggestion and put everything in one mutex and changed make_client to hold the mutex for the entire operation (which should be quick).

Split up `RemoteSettingServiceInner` into multiple structs, each with
their own Mutex and add a bit of policy around locking them.  Right now
this is just enforced by putting all the methods that lock them in one
impl block.

The issue we're trying to avoid is having `RemoteSettingService::sync`
block `RemoteSettingService::make_client`.

Also, start using `viaduct::Client` which should be possible now since
all applications are using the new backend.
@bendk bendk force-pushed the bdk/push-qyzkwrspulzl branch from d924c1f to 58dc98d Compare July 15, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants