Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit DbInner Arc usages #1480

Open
data-sync-user opened this issue Sep 25, 2023 · 0 comments
Open

Revisit DbInner Arc usages #1480

data-sync-user opened this issue Sep 25, 2023 · 0 comments

Comments

@data-sync-user
Copy link
Collaborator

Rust’s 1.72 clippy now issues a warning about all 3 of our DbInner Arc usages:

  --> tokenserver-db/src/models.rs:80:20
   |
80 |             inner: Arc::new(inner),
   |                    ^^^^^^^^^^^^^^^
   |
   = note: the trait `Sync` is not implemented for `DbInner`
   = note: required for `Arc<DbInner>` to implement `Send` and `Sync`
   = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
   = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings`This is a good warning, however it’s not 100% valid for our Mysql based implementations (sync and tokenserver) because we force `Send` on their overall `Db` structs (via unsafe so we can send their calls to a thread). We'll mark these to skip the warnings going forward but we could consider alternative ways of doing this that wouldn’t trigger clippy.

Basically we want to force Send for the sake of sending these calls to a thread. For Arc to be Send it requires the Inner fields to be Sync. So we essentially want to unsafe force Sync for the ability to Send. This is safe for us because we only send these values to our threadpool which blocks the async task until it’s finished running.

The warning suggests we don’t actually need the Arc for the spanner impl because it doesn’t implement Send/Sync.

So 2 parts:

  • Replace Spanner’s Arc w/ Rc
  • Consider alternatives to how we unsafe the Send for our blocking threadpool implementations

┆Issue is synchronized with this Jira Task

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

No branches or pull requests

1 participant