[Feature]: Enforce service thread safety through automatic Send and Sync implementations

Open
#2,027 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@Javagedes is already working on this.

Since Nov 23, 2026.

Assessment

This issue has not been assessed yet.

Description

state:needs-triage type:feature-request urgency:medium
Feature Overview

Require the compiler to verify that Service<T> is Send + Sync, rather than asserting thread safety through unconditional unsafe implementations.

Services use Arc<T> for shared ownership and expose shared access through &T. However, atomic reference counting and shared-only access do not make arbitrary service implementations thread-safe. Interior mutability and destruction must also be safe across threads.

Solution Overview

Remove the unconditional unsafe Send and Sync implementations from Service<T> and allow Rust to derive these auto traits from its Arc field.

Because Arc<T> implements Send + Sync only when T: Send + Sync, require those bounds at the service abstraction boundary:

pub struct Service<T: ?Sized + Send + Sync + 'static> {
    value: Arc<T>,
}

Propagate these requirements through service registration, conversions, parameter implementations, and generated code.

For trait-object services, express the requirement through service trait supertraits:

pub trait ExampleService: Send + Sync {
    fn perform_work(&self);
}

This allows consumers to retain the existing form: Service<dyn ExampleService>.

Validation should include:

  • Compile-time assertions that supported concrete and trait-object service handles implement Send + Sync.
  • Compile-fail coverage rejecting service implementations that do not satisfy the bounds.
  • Existing service registration, cloning, and destruction tests.
  • Relevant workspace checks and supported-target builds.
Alternatives Considered
  • Keep the unconditional unsafe implementations: Relies on an unenforced contract for every service implementation and permits non-thread-safe implementations to cross threads through safe APIs.
  • Remove unsafe implementations without requiring bounds on services: Allows conditional auto-trait implementations, but still permits non-thread-safe services to be registered. This does not establish a uniform thread-safety requirement.
  • Require all components to implement Send + Sync: Broader than necessary. Components are managed on the BSP; services are the independently shared abstraction.
Urgency

Medium

Are you going to implement the feature request?

I will implement the feature

Do you need maintainer feedback?

No maintainer feedback needed

Anything else?

No response

Dominant language
Rust
Stars
568
Forks
63
Avg merge
1d 16h
Merged PRs (30d)
60

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenDevicePartnership/patina

All issues in OpenDevicePartnership/patina

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.