Skip to content

Commit c06d4c2

Browse files
GudahttMajorLift
authored andcommitted
Fix lookupNetwork deadlock (#948)
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.
1 parent 06e76ca commit c06d4c2

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/network/NetworkController.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,20 +326,24 @@ export class NetworkController extends BaseController<
326326
this.ethQuery.sendAsync(
327327
{ method: 'net_version' },
328328
(error: Error, network: string) => {
329-
if (this.state.network === network) {
330-
return;
329+
try {
330+
if (this.state.network === network) {
331+
return;
332+
}
333+
334+
this.update((state) => {
335+
state.network = error
336+
? /* istanbul ignore next*/ 'loading'
337+
: network;
338+
});
339+
340+
this.messagingSystem.publish(
341+
`NetworkController:providerChange`,
342+
this.state.provider,
343+
);
344+
} finally {
345+
releaseLock();
331346
}
332-
333-
this.update((state) => {
334-
state.network = error ? /* istanbul ignore next*/ 'loading' : network;
335-
});
336-
337-
this.messagingSystem.publish(
338-
`NetworkController:providerChange`,
339-
this.state.provider,
340-
);
341-
342-
releaseLock();
343347
},
344348
);
345349
}

0 commit comments

Comments
 (0)