Skip to content

HTMLRewriter: no more write promise chaining - #3776

Merged
npaun merged 1 commit into
mainfrom
npaun/htmlrewriter-stack-fix
Apr 8, 2025
Merged

npaun merged 1 commit into
mainfrom
npaun/htmlrewriter-stack-fix

Conversation

@npaun

@npaun npaun commented Mar 21, 2025

Copy link
Copy Markdown
Member

This PR follows up on #3758 to provide a more solid fix.

The chained writePromise is no longer used. Instead, every time lol_html generates output, we store it in outputBuffer (just a kj::Vector). outputBuffer is flushed to the output sink after each handler thunk. If more than 128 MB accumulates in outputBuffer, we poison the Rewriter, preventing users from causing arbitrary memory usage.

As a result of this PR, the test stackOverflow1 now passes (lots of output from one handler), and stackOverflow2 continues to pass.

@npaun
npaun requested review from harrishancock and jasnell March 21, 2025 21:09
@npaun
npaun requested review from a team as code owners March 21, 2025 21:09
@npaun
npaun force-pushed the npaun/htmlrewriter-stack-fix branch 2 times, most recently from 18460fb to cc97d90 Compare March 21, 2025 21:11
Comment thread src/workerd/api/html-rewriter.c++
Comment thread src/workerd/api/tests/htmlrewriter-test.js Outdated
Comment thread src/workerd/api/html-rewriter.c++ Outdated
Comment thread src/workerd/api/html-rewriter.c++ Outdated
@npaun
npaun force-pushed the npaun/htmlrewriter-stack-fix branch from cc97d90 to 2d9d4e5 Compare March 25, 2025 20:43
@npaun

npaun commented Mar 25, 2025

Copy link
Copy Markdown
Member Author

rebasin'

@npaun
npaun force-pushed the npaun/htmlrewriter-stack-fix branch 3 times, most recently from 2d9d4e5 to f3d5c88 Compare March 31, 2025 14:03
Comment thread src/workerd/api/html-rewriter.c++ Outdated
@npaun
npaun force-pushed the npaun/htmlrewriter-stack-fix branch from f3d5c88 to be6826d Compare April 8, 2025 01:40
@npaun

npaun commented Apr 8, 2025

Copy link
Copy Markdown
Member Author

rebased

@npaun
npaun force-pushed the npaun/htmlrewriter-stack-fix branch from be6826d to 0875fc1 Compare April 8, 2025 01:48
@npaun
npaun force-pushed the npaun/htmlrewriter-stack-fix branch from 0875fc1 to 59e1f9d Compare April 8, 2025 01:51
@npaun
npaun merged commit 414375c into main Apr 8, 2025
@npaun
npaun deleted the npaun/htmlrewriter-stack-fix branch April 8, 2025 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants