-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[PM-26049] Auto key not stored due to vault timeout write vs read race condition for cli #17707
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
base: main
Are you sure you want to change the base?
[PM-26049] Auto key not stored due to vault timeout write vs read race condition for cli #17707
Conversation
|
Claude finished @mzieniukbw's task —— View job Code Review SummaryI've analyzed the PR that fixes a race condition where auto keys weren't being stored due to vault timeout being null during read operations. The solution correctly addresses the issue by filtering out null values from the observable stream. PR Documentation QualityThe PR documentation is excellent:
FindingsFinding 1: The core fix correctly addresses the race condition by filtering null vault timeout values Details: The change in
Reference: libs/key-management/src/key.service.ts:691-695 Finding 2: The Details: In
However, the comment on line 140 says "As a side effect" but Suggestion: Update comment from "As a side effect, set..." to "Set the new value determined by determineVaultTimeout into state if it's different from the current" Reference: libs/common/src/key-management/vault-timeout/services/vault-timeout-settings.service.ts:139-145 Finding 3: Test improvements appropriately initialize vault timeout state Details: Both test files now properly initialize
These changes ensure tests don't encounter the same race condition the PR is fixing. The values chosen are appropriate for each context:
Minor: The electron test cleanup removed nested describe blocks and redundant tests, which improves test clarity and removes duplication. References:
Finding 4: Export of Details: The PR exports While the comment is helpful, exposing internal state definitions for tests is generally not ideal. Consider whether the test could use a different approach (e.g., mocking or a test utility) rather than importing internal state definitions. However, this is a minor architectural concern and doesn't impact the correctness of the fix. Reference: libs/common/src/key-management/vault-timeout/index.ts:12-13 Security Considerations✅ No security concerns identified
Architecture & Best Practices✅ Observable pattern correctly implemented
✅ Test coverage maintained
SummaryThis is a well-executed fix for a race condition bug. The core solution (filtering null values) is correct and addresses the root cause. The PR includes appropriate test updates and good documentation. The only minor suggestion is to update the comment in Overall assessment: Approve with minor comment improvement suggestion |
|
Great job! No new security vulnerabilities introduced in this pull request |

🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-26049
📔 Objective
Auto (user) key is (sometimes) not stored due to vault timeout being null.
This happens due to race condition on the storage write vs read. The read is hot observable, so getting value via
firstValueFrommight return null.Since vault timeout is not supposed to be null (since we always have a non-null default for all clients), adding a filter for non-nullability is enough to make sure the actual value is returned, before deciding whether to store the auto key.
Writing the vault timeout (default when not set) happens as a "side effect" of
getVaultTimeoutByUserId$, which is not great, but since we require it (firstValueFrom) just before identity token request (before parsing it and setting user keys to state), the vault timeout is reliably stored in state for the first time when not set, duringbw loginand always before the auto key storage.Tested login, unlock, sync, changing vault timeout in settings from and to Never on all clients, restarting app to see if it starts unlocked.
📸 Screenshots
⏰ Reminders before review
🦮 Reviewer guidelines
:+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