chore: add re-entry guard to StreamManager::optimize#1052
chore: add re-entry guard to StreamManager::optimize#1052
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-019cf4c5-1963-70f9-89b3-de136ea15720 Co-authored-by: Amp <amp@ampcode.com>
Manual Deploy AvailableYou can trigger a manual deploy of this PR branch to testnet: Alternative: Comment
Comment updated automatically when the PR is synchronized. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe changes add re-entrancy protection to the ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the tone of the review comments and chat replies.Configure the |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@magicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rs`:
- Around line 409-410: The optimize() method sets self.optimizing = true but can
return early on errors (e.g., when awaiting subscribe(...).await? or other
failure paths) leaving optimizing stuck true; update optimize() to ensure
self.optimizing is reset to false on every exit path (both success and error) —
use a scoped guard or finally-style cleanup (e.g., a Drop guard or a defer-like
closure) to set self.optimizing = false, and apply the same pattern to the
surrounding async flows that set optimizing (references: optimize(), the
subscribe(...).await? call site, and any places that assign self.optimizing =
true) so no early-return path leaves optimizing true.
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 22fffb2a-0d0a-43af-83c0-255d94afb203
📒 Files selected for processing (1)
magicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rs
magicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rs
Outdated
Show resolved
Hide resolved
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 2 file(s) based on 1 unresolved review comment. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 2 file(s) based on 1 unresolved review comment. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@magicblock-chainlink/src/remote_account_provider/chain_laser_actor/mock.rs`:
- Around line 137-143: The code returns a non-existent error variant
RemoteAccountProviderError::Other causing a compile error; replace that with an
existing variant such as RemoteAccountProviderError::AccountSubscriptionsFailed
(or another appropriate existing variant) in the mock subscribe failure branch
so the function returns a valid enum variant; update the Err(...) in the
should_fail block to construct
RemoteAccountProviderError::AccountSubscriptionsFailed with a descriptive
message (e.g., "mock subscribe failure") so the mock compiles and preserves the
original error text.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: f6cd5928-ef79-44f3-98c6-49d53c8f7099
📒 Files selected for processing (2)
magicblock-chainlink/src/remote_account_provider/chain_laser_actor/mock.rsmagicblock-chainlink/src/remote_account_provider/chain_laser_actor/stream_manager.rs
magicblock-chainlink/src/remote_account_provider/chain_laser_actor/mock.rs
Outdated
Show resolved
Hide resolved
This reverts commit 1603ca7.
Amp-Thread-ID: https://ampcode.com/threads/T-019cf647-2d0b-741e-9859-d48db0bfb58f Co-authored-by: Amp <amp@ampcode.com>
Summary
Add a defensive re-entry guard to
StreamManager::optimizeto protect against concurrent callsand future refactoring risks.
Details
The
optimize()method inStreamManageroperates on mutable state and is intended to becalled only once at a time within the single
tokio::select!loop. While re-entry should currentlybe impossible due to the
&mut selfreceiver, this change adds anoptimizingboolean flag as adefensive measure.
Summary by CodeRabbit
Release Notes