Skip to content

Commit

Permalink
Fix lookupNetwork deadlock
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 f50d3fd
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 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;
}

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

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

releaseLock();
// 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();
// }
},
);
}
Expand Down

0 comments on commit f50d3fd

Please sign in to comment.