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

SM-805: Put ApiConfigurations & EncryptionSettings in Client behind RwLock & Arc #70

Closed
wants to merge 1 commit into from

Conversation

coltonhurst
Copy link
Member

Type of change

- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Make client functions immutable

Code changes

  • file.ext: Description of what was changed and why

Screenshots

Before you submit

  • Please add unit tests where it makes sense to do so (encouraged but not required)

@coltonhurst coltonhurst self-assigned this Jun 14, 2023
@coltonhurst coltonhurst changed the title SM-805: Make Client Functions Immutable SM-805: Put ApiConfigurations & EncryptionSettings in Client behind RwLock & Arc Jun 14, 2023
@Hinton
Copy link
Member

Hinton commented Feb 6, 2024

Closing this since we're exploring other solutions.

@Hinton Hinton closed this Feb 6, 2024
dani-garcia added a commit that referenced this pull request Jun 13, 2024
## 📔 Objective

We're having some deadlock problems with the Passkey API by calling
certain SDK functions on the `passkey-rs` callbacks. These issues are
caused because we're holding a reference to the RwLock during the
execution of the Passkey operation and so calling into the SDK from
inside that will deadlock.

To solve it we can't just use a lock at the client level, and so we need
to move to using interior mutability, I've revived an old PR (#70) where
we started doing that.

This PR is split into two commits, for ease of review: 
- [Remove all the muts and locks for
uniffi](c56add5):
This removes the use of RwLock in bitwarden-uniffi and the `&mut`
references used in the bitwarden Client API. Note that this alone won't
compile.
- [Make client internally
mutable](f61d104):
Implements RwLocks in Client to make it internally mutable.


Some notes of what the change entails:
- I had to wrap `EncryptionSettings` in a `RwLock<Arc<>>` to get the API
working, this is quite unfortunate as it forces us to clone
`EncryptionSettings` to modify it when calling `set_org_keys`. We can't
wrap the `org_keys` in a `RwLock` as we will get lifetime issues in
`get_key`. I think the best solution for this will be the work on
creating a Crypto store that only returns opaque key references, so we
might want to prioritize that.
- I extracted `external_client` from `ApiConfigurations`, as it's never
mutated and it allows us to keep the same API for `get_http_client`

I hate that `Mutex` and `RwLock` return a Result in case they are
poisoned, that's never our case and it makes their usage so cumbersome 😢

Note: I've tried to change the smallest amount of code to make the
change, so the secrets manager APIs (and bitwarden-json) are still
mutable. If we're okay with these changes I can go back to update those
in a separate PR.

## ⏰ Reminders before review

- Contributor guidelines followed
- All formatters and local linters executed and passed
- Written new unit and / or integration tests where applicable
- Protected functional changes with optionality (feature flags)
- Used internationalization (i18n) for all UI strings
- CI builds passed
- Communicated to DevOps any deployment requirements
- Updated any necessary documentation (Confluence, contributing docs) or
informed the documentation
  team

## 🦮 Reviewer guidelines

<!-- Suggested interactions but feel free to use (or not) as you desire!
-->

- 👍 (`:+1:`) or similar for great changes
- 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info
- ❓ (`:question:`) for questions
- 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry
that's not quite a confirmed
  issue and could potentially benefit from discussion
- 🎨 (`:art:`) for suggestions / improvements
- ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or
concerns needing attention
- 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or
indications of technical debt
- ⛏ (`:pick:`) for minor or nitpick changes
@coltonhurst coltonhurst deleted the sm/SM-805 branch August 26, 2024 13:29
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