Repository navigation
Reproduce HTMLRewriter stack overflow using JS code + quick fix - #3758
Merged
Merged
Conversation
jasnell
approved these changes
Mar 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds two tests that cause a stack overflow in workerd:
stackOverflow1: A single replacement function generates a lot of output bytesstackOverflow2: The replacement function runs many timesI've also implemented the idea we came up with to limit the depth of the promise chain: waiting on
writePromiseafter every thunk call. As expected, this fixesstackOverflow2but notstackOverflow1. Therefore I commented outstackOverflow1for now.I'd like to merge this quick fix to see if the sentry errors go away, but it's not a full fix. The next step would be to implement an internal buffer in
Rewriterand flush that to theinner(output sink) after each thunk call.There's also another potential situation where a ReadableStream is used to provide the replacement. In another PR, we could implement back pressure to avoid too much data from being buffered at once.