Commit 0106a5f
authored
fix: Network controller race condition after state update (#5122)
## Explanation
Fixes a race condition where:
- You update a network with a new endpoint.
- In the `stateChange` subscription callback, call
`getNetworkConfigurationByNetworkClientId` on the new endpoint.
- It returns undefined.
This occurs because the `network client id -> network configuration` map
was being built *after* the state update, so it was not ready at the
time of the `stateChange` event.
The fix involves moving this map building inside the state update, so
that its built by the time `stateChange` fires. But also requires deep
cloning the state before building the map from it. Otherwise we get
`Cannot perform 'get' on a proxy that has been revoked` when referencing
the ephemeral `state` lambda.
## References
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?
For example:
* Fixes #12345
* Related to #67890
-->
## Changelog
<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.
(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)
Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).
If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.
Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->
### `@metamask/network-controller`
- **FIXED**: A race condition when calling
`getNetworkConfigurationByNetworkClientId` in response to a
`stateChange` event adding a new endpoint to a network.
## Checklist
- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes1 parent d6a4c8f commit 0106a5f
File tree
2 files changed
+60
-15
lines changed- packages/network-controller
- src
- tests
2 files changed
+60
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
1636 | 1637 | | |
1637 | 1638 | | |
1638 | 1639 | | |
1639 | | - | |
1640 | | - | |
1641 | | - | |
1642 | | - | |
1643 | | - | |
1644 | 1640 | | |
1645 | 1641 | | |
1646 | 1642 | | |
| |||
1919 | 1915 | | |
1920 | 1916 | | |
1921 | 1917 | | |
1922 | | - | |
1923 | | - | |
1924 | | - | |
1925 | | - | |
1926 | | - | |
1927 | 1918 | | |
1928 | 1919 | | |
1929 | 1920 | | |
| |||
1983 | 1974 | | |
1984 | 1975 | | |
1985 | 1976 | | |
1986 | | - | |
1987 | | - | |
1988 | | - | |
1989 | | - | |
1990 | | - | |
1991 | 1977 | | |
1992 | 1978 | | |
1993 | 1979 | | |
| |||
2500 | 2486 | | |
2501 | 2487 | | |
2502 | 2488 | | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
2503 | 2494 | | |
2504 | 2495 | | |
2505 | 2496 | | |
| |||
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11338 | 11338 | | |
11339 | 11339 | | |
11340 | 11340 | | |
| 11341 | + | |
| 11342 | + | |
| 11343 | + | |
| 11344 | + | |
| 11345 | + | |
| 11346 | + | |
| 11347 | + | |
| 11348 | + | |
| 11349 | + | |
| 11350 | + | |
| 11351 | + | |
| 11352 | + | |
| 11353 | + | |
| 11354 | + | |
| 11355 | + | |
| 11356 | + | |
| 11357 | + | |
| 11358 | + | |
| 11359 | + | |
| 11360 | + | |
| 11361 | + | |
| 11362 | + | |
| 11363 | + | |
| 11364 | + | |
| 11365 | + | |
| 11366 | + | |
| 11367 | + | |
| 11368 | + | |
| 11369 | + | |
| 11370 | + | |
| 11371 | + | |
| 11372 | + | |
| 11373 | + | |
| 11374 | + | |
| 11375 | + | |
| 11376 | + | |
| 11377 | + | |
| 11378 | + | |
| 11379 | + | |
| 11380 | + | |
| 11381 | + | |
| 11382 | + | |
| 11383 | + | |
| 11384 | + | |
| 11385 | + | |
| 11386 | + | |
| 11387 | + | |
| 11388 | + | |
| 11389 | + | |
| 11390 | + | |
| 11391 | + | |
| 11392 | + | |
| 11393 | + | |
| 11394 | + | |
11341 | 11395 | | |
11342 | 11396 | | |
11343 | 11397 | | |
| |||
0 commit comments