Skip to content

Commit

Permalink
Fix lookupNetwork deadlock (#948)
Browse files Browse the repository at this point in the history
This fixes a deadlock accidentally introduced as part of #903. That PR
introduced an early exit in the `net_version` callback that did not
release the lock.

A `try...finally` block has been introduced to ensures the lock is
always released.
  • Loading branch information
Gudahtt committed Nov 8, 2022
1 parent cf76cbd commit b3635c9
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/network/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,24 @@ export class NetworkController extends BaseController<
this.ethQuery.sendAsync(
{ method: 'net_version' },
(error: Error, network: string) => {
if (this.state.network === network) {
return;
try {
if (this.state.network === network) {
return;
}

this.update((state) => {
state.network = error
? /* istanbul ignore next*/ 'loading'
: network;
});

this.messagingSystem.publish(
`NetworkController:providerChange`,
this.state.provider,
);
} finally {
releaseLock();
}

this.update((state) => {
state.network = error ? /* istanbul ignore next*/ 'loading' : network;
});

this.messagingSystem.publish(
`NetworkController:providerChange`,
this.state.provider,
);

releaseLock();
},
);
}
Expand Down

0 comments on commit b3635c9

Please sign in to comment.