Repository navigation
Commit 56918c6
fix(server): close serialized iterators on stream abandonment (#3628)
* fix(server): close serialized iterators on stream abandonment (#3626)
A memo or projection whose compute yields an async iterable serializes a
tapped iterator into the stream. Cancelling the readable or a throwing
pipe sink disposes the render, but the tapped iterator kept delegating
next() to the source, so seroval pulled it for as long as the source
lived and the generator's finally never ran. The tapped iterator now
answers done and calls the source's return() once its computation is
disposed. The projection pump already stopped on disposal but left its
source open; it now closes it too.
* fix: address review findings
The tapped iterator replays its first value before it checks for
disposal, so the value the HTML was rendered from always ships. The
source's `return()` runs at most once per tapped iterator, whether the
close comes from a pull after disposal or from the wrapper's own
`return()`. The spec waits for the source's first pull before it cancels
and for the source's `finally` before it asserts, instead of fixed
delays, and it also reads each stream to the end and checks that every
value arrives.
* fix(web): close the serializer when a stream render is abandoned (#3626)
The tapped iterator's disposed check runs on the next pull, so a source
whose pending `next()` never settles was never returned — the gap the PR
body's "Open" section names. `renderToStream`'s `abandon()` now closes the
serializer after marking the render dead: seroval's `close()` runs every
pending write's cleanup, which calls `return()` on each serialized async
iterator immediately, and its `onDone` sees `dead` and skips the shell.
`close()` is contained (a custom serializer's `close` is optional and must
not escape the teardown; a throw routes to the server error hook when one
exists). After the close, the render's remaining writes go to an
abandoned serializer that owns their rejections — a closed serializer
drops writes without looking, which turned a rejecting `<key>_fr` into an
unhandled rejection — and the shell stub batch is drained and disabled.
`closeAsyncIterator` also contains a synchronously throwing `return()`,
so the pump paths (called from `.then` continuations) cannot leak one.
Tests: the never-settling source across `getReader().cancel()`, a
rejecting `pipeTo` writable, a throwing `pipe` sink, the async-memo
flatten path, a custom `options.serializer` `close()`, the render-failure
path (never rejects, one `failed`), and a synchronously throwing
`return()`.
Co-authored-by: Claude via Cursor <[email protected]>
---------
Co-authored-by: Ryan Carniato <[email protected]>
Co-authored-by: Claude via Cursor <[email protected]>1 parent fb35efb commit 56918c6
4 files changed
Lines changed: 613 additions & 18 deletions
File tree
- .changeset
- packages
- solid/src/server
- web
- src
- test/server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1507 | 1507 | | |
1508 | 1508 | | |
1509 | 1509 | | |
| 1510 | + | |
1510 | 1511 | | |
1511 | 1512 | | |
1512 | 1513 | | |
1513 | 1514 | | |
1514 | 1515 | | |
1515 | 1516 | | |
1516 | 1517 | | |
| 1518 | + | |
1517 | 1519 | | |
1518 | 1520 | | |
1519 | | - | |
1520 | | - | |
1521 | | - | |
| 1521 | + | |
1522 | 1522 | | |
1523 | 1523 | | |
1524 | 1524 | | |
| |||
1728 | 1728 | | |
1729 | 1729 | | |
1730 | 1730 | | |
| 1731 | + | |
1731 | 1732 | | |
1732 | 1733 | | |
1733 | 1734 | | |
| |||
1739 | 1740 | | |
1740 | 1741 | | |
1741 | 1742 | | |
| 1743 | + | |
1742 | 1744 | | |
1743 | 1745 | | |
1744 | 1746 | | |
| |||
1749 | 1751 | | |
1750 | 1752 | | |
1751 | 1753 | | |
1752 | | - | |
1753 | | - | |
1754 | | - | |
| 1754 | + | |
1755 | 1755 | | |
1756 | 1756 | | |
1757 | 1757 | | |
| |||
1832 | 1832 | | |
1833 | 1833 | | |
1834 | 1834 | | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
1835 | 1839 | | |
1836 | | - | |
1837 | | - | |
1838 | | - | |
1839 | | - | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
1840 | 1857 | | |
1841 | 1858 | | |
1842 | 1859 | | |
| |||
2456 | 2473 | | |
2457 | 2474 | | |
2458 | 2475 | | |
| 2476 | + | |
2459 | 2477 | | |
2460 | 2478 | | |
2461 | 2479 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1890 | 1890 | | |
1891 | 1891 | | |
1892 | 1892 | | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
1893 | 1898 | | |
1894 | 1899 | | |
1895 | 1900 | | |
1896 | 1901 | | |
1897 | | - | |
1898 | | - | |
1899 | | - | |
1900 | | - | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
1901 | 1909 | | |
1902 | 1910 | | |
1903 | 1911 | | |
| |||
1919 | 1927 | | |
1920 | 1928 | | |
1921 | 1929 | | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
1922 | 1943 | | |
1923 | 1944 | | |
1924 | 1945 | | |
| |||
1957 | 1978 | | |
1958 | 1979 | | |
1959 | 1980 | | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
1960 | 2012 | | |
1961 | 2013 | | |
1962 | 2014 | | |
| |||
2225 | 2277 | | |
2226 | 2278 | | |
2227 | 2279 | | |
2228 | | - | |
| 2280 | + | |
2229 | 2281 | | |
2230 | 2282 | | |
2231 | 2283 | | |
| |||
2565 | 2617 | | |
2566 | 2618 | | |
2567 | 2619 | | |
2568 | | - | |
2569 | | - | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
2570 | 2623 | | |
2571 | 2624 | | |
2572 | 2625 | | |
| |||
2613 | 2666 | | |
2614 | 2667 | | |
2615 | 2668 | | |
2616 | | - | |
| 2669 | + | |
| 2670 | + | |
2617 | 2671 | | |
2618 | 2672 | | |
2619 | 2673 | | |
| |||
0 commit comments