Skip to content

[PM-20615] Only process incoming messages once #264

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

Merged
merged 42 commits into from
Jun 11, 2025

Conversation

coroiu
Copy link
Contributor

@coroiu coroiu commented May 6, 2025

🎟️ Tracking

📔 Objective

  • Create a new thread/task and delegate message processing to it
  • Make sure CryptoProvider only sees each incoming message once
  • Make everything multi-thread safe
    • Enables a single thread to take ownership of message processing
    • but will also allow us to use the IPC framework with BitwardenClient

⏰ 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

  • 👍 (:+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

@coroiu coroiu requested a review from a team as a code owner May 6, 2025 13:27
@coroiu coroiu requested a review from addisonbeck May 6, 2025 13:27
@coroiu coroiu requested a review from dani-garcia May 6, 2025 13:29
@coroiu
Copy link
Contributor Author

coroiu commented May 6, 2025

Sorry for assigning this to you too @dani-garcia, but I don't think anyone else has experience with Send + Sync

Copy link
Contributor

github-actions bot commented May 6, 2025

Logo
Checkmarx One – Scan Summary & Details30ce46fc-9669-4680-abd8-9afd745a558a

Great job, no security vulnerabilities found in this Pull Request

@coroiu
Copy link
Contributor Author

coroiu commented May 6, 2025

I'm debugging the tests now but apparently they only fail when you run cargo test and not cargo test -p bitwarden-ipc --lib

Edit: Fixed

Copy link

codecov bot commented May 6, 2025

Codecov Report

Attention: Patch coverage is 76.32653% with 58 lines in your changes missing coverage. Please review.

Project coverage is 70.29%. Comparing base (8fa77eb) to head (a439d83).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/bitwarden-ipc/src/wasm/ipc_client.rs 0.00% 22 Missing ⚠️
crates/bitwarden-ipc/src/ipc_client.rs 91.32% 17 Missing ⚠️
...es/bitwarden-ipc/src/wasm/communication_backend.rs 0.00% 17 Missing ⚠️
...tes/bitwarden-ipc/src/traits/session_repository.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #264      +/-   ##
==========================================
- Coverage   70.32%   70.29%   -0.03%     
==========================================
  Files         217      216       -1     
  Lines       16992    17060      +68     
==========================================
+ Hits        11949    11992      +43     
- Misses       5043     5068      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

(cherry picked from commit 875c3a9)
@coroiu coroiu requested review from dani-garcia and removed request for addisonbeck May 27, 2025 15:12
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Some comments about the locking we're doing, but otherwise LGTM

@@ -1,3 +1,8 @@
#[cfg(all(target_arch = "wasm32", not(feature = "wasm")))]
compile_error!(
"The `wasm` feature must be enabled to use the `bitwarden-ipc` crate in a WebAssembly environment."
Copy link
Member

Choose a reason for hiding this comment

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

bitwarden-threading doesn't have any feature defined in cargo.toml, does it? Why is this needed?

I wonder if we should decide whether we want to use target_arch = "wasm32" or feature = "wasm" and just update the whole repo to be consistent.

Copy link
Contributor Author

@coroiu coroiu May 28, 2025

Choose a reason for hiding this comment

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

I added a wasm feature. I needed to add it because the crates that depend on threading use features and so I had to either convert them to target_arch too or convert threading to use feature.

Yeah, I think features has some advantage but I can't remember what 🙃 So far adding the wasm flag to a non-wasm build (which we do when we run cargo test --all-features) hasn't caused any issues because wasm-bindgen has a goal to always compile on all target and instead throw runtime errors if you try to use it on an unsupported target. But now, we have this thing:

#[cfg(not(target_arch = "wasm32"))]
use tokio::task::spawn_local;
#[cfg(all(target_arch = "wasm32", feature = "wasm"))]
use wasm_bindgen_futures::spawn_local;

which is actively used in unit-tests and so all of a sudden we cannot just do

#[cfg(not(featgure = "wasm"))]
use tokio::task::spawn_local;
#[cfg(feature = "wasm")]
use wasm_bindgen_futures::spawn_local;

because that would cause wasm_bindgen_futures::spawn_local to be called during a regular unit test which would cause a runtime error.

So either we remove wasm from cargo test (cargo test --all-features --except wasm ???) or we use target_arch

@coroiu coroiu requested a review from dani-garcia May 28, 2025 08:14
dani-garcia
dani-garcia previously approved these changes May 28, 2025
Copy link

@coroiu coroiu requested a review from dani-garcia June 11, 2025 11:28
@coroiu coroiu merged commit 1fa0f7a into main Jun 11, 2025
43 checks passed
@coroiu coroiu deleted the PM-20615-only-process-incoming-messages-once branch June 11, 2025 13:49
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