Commit 08299db
authored
fix: Attach error handler to RPC stream (#3898)
When the execution environment fails on mobile (we still don't know the
cause of this) we were seeing uncaught "Premature close" errors, which
ends up crashing the app.
The issue is that all streams are destroyed when the Snap terminates (as
it does if it cannot initialize). Most streams already have error
handling setup via `pipeline` and if the Snap in question has already
run this applies to the RPC stream too. The problem is that if the Snap
never starts, the RPC stream also never has any error handlers attached,
so instead it bubbles up the error.
This PR fixes that by attaching an error handler to the RPC stream after
it has been created.
https://consensyssoftware.atlassian.net/browse/WPC-516
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches snap execution stream lifecycle in `AbstractExecutionService`,
which is central to snap RPC plumbing; while the change is small, it
could affect error propagation/logging during initialization and
teardown.
>
> **Overview**
> Prevents uncaught RPC stream errors during snap startup/termination by
attaching an `error` listener to the JSON-RPC mux stream as soon as it’s
created, filtering out expected `Premature close` noise while logging
other failures.
>
> Adds a regression test that simulates a failed/unreachable execution
environment and asserts the request fails cleanly without throwing
`Premature close`, and relaxes test utilities to accept any
`AbstractExecutionService` instance for injection.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c8458fa. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 5a88d61 commit 08299db
4 files changed
Lines changed: 69 additions & 4 deletions
File tree
- packages/snaps-controllers
- src
- services
- snaps
- test-utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
323 | 331 | | |
324 | 332 | | |
325 | 333 | | |
| |||
Lines changed: 58 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
96 | | - | |
97 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
98 | 104 | | |
99 | 105 | | |
100 | 106 | | |
| |||
1854 | 1860 | | |
1855 | 1861 | | |
1856 | 1862 | | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
1857 | 1913 | | |
1858 | 1914 | | |
1859 | 1915 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
691 | 692 | | |
692 | 693 | | |
693 | 694 | | |
694 | | - | |
| 695 | + | |
695 | 696 | | |
696 | 697 | | |
697 | 698 | | |
| |||
0 commit comments