Skip to content

Comments

Better lock handling on ethui_networks#1504

Merged
naps62 merged 1 commit intomainfrom
fix-locks
Nov 26, 2025
Merged

Better lock handling on ethui_networks#1504
naps62 merged 1 commit intomainfrom
fix-locks

Conversation

@naps62
Copy link
Member

@naps62 naps62 commented Nov 26, 2025

I identified a few places where locks on ethui_networks::Networks were being held for too long (during network requests) which is the likely cause of some UI hang-ups in recent versions

The new approach avoids locking into the global networks object by cloning the network itself, or fetching a provider directly in an auxiliary function

in a future update, we'll likely migrate this to kameo as well to ensure this kind of bug can't happen so easily

Copilot AI review requested due to automatic review settings November 26, 2025 15:57
@naps62 naps62 added the B-bugfix Something is working again label Nov 26, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors lock handling for the ethui_networks::Networks global state to prevent UI hang-ups caused by holding locks during async network operations. The solution introduces helper functions that clone network data or providers after briefly acquiring and releasing the lock, ensuring locks are never held across await points.

Key changes:

  • Added public helper functions get_network() and get_provider() in the networks crate that handle lock acquisition/release
  • Replaced all instances where locks were held during network requests with calls to these new helpers
  • Added _cloned() variants of getter methods to make cloning explicit and prevent lock retention

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/networks/src/lib.rs Added get_network(), get_provider(), and _cloned() helper methods; removed chain_id_from_provider()
crates/networks/src/commands.rs Updated to use get_network_by_dedup_chain_id_cloned() and moved provider connection logic inline to avoid holding lock
crates/types/src/prelude.rs Added Ethereum and RootProvider to prelude exports to support new helper function signatures
crates/sync/src/utils.rs Replaced local provider() helper with calls to ethui_networks::get_provider()
crates/sync/src/commands.rs Replaced lock-holding pattern with get_network() helper; removed unused imports
crates/rpc/src/utils.rs Simplified to use get_provider() helper instead of manually managing lock
crates/forge/src/utils.rs Replaced error-handling and lock management with get_provider() helper; removed unused imports
crates/ws/src/peers.rs Store lock result before conditional check to release lock earlier; reordered imports
bin/src/commands.rs Updated to use get_network() helper; removed unused imports
bin/src/app.rs Added conditional compilation guards for Runtime and TauriPlugin imports only used with aptabase feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@naps62 naps62 merged commit a174fd9 into main Nov 26, 2025
13 of 14 checks passed
@naps62 naps62 deleted the fix-locks branch November 26, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-bugfix Something is working again

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant