Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The fetch process hangs when a microtask invokes fetch via document.write #2893

Open
trflynn89 opened this issue Dec 12, 2024 · 0 comments
Open
Labels
bug Something isn't working has repro We have a way to reproduce this bug.

Comments

@trflynn89
Copy link
Contributor

trflynn89 commented Dec 12, 2024

Repro HTML:

<iframe id="iframe"></iframe>
<script>
    queueMicrotask(() => {
        iframe.contentDocument.write("<script src=empty.js><\/script>");
        iframe.contentDocument.close();
    });
</script>

Where empty.js is an empty file.


All promise callbacks are executed on the microtask queue by way of vm.host_enqueue_promise_job. Only one microtask is allowed to execute at a time (see EventLoop::perform_a_microtask_checkpoint).

So, when we write to the iframe, we will eventually fetch the script's source URL in HTMLScriptElement::prepare_script. The call to document.write will block until this fetch is complete here:

// spin the event loop until the parser's Document has no style sheet that is blocking scripts
// and the script's ready to be parser-executed becomes true.
main_thread_event_loop().spin_until(GC::create_function(heap(), [&] {
return !m_document->has_a_style_sheet_that_is_blocking_scripts() && the_script->is_ready_to_be_parser_executed();
}));

But because we are already in a microtask, the promises involved in this inner fetch are not able to complete, as those microtasks are effectively blocked.

This is reached in the following WPT tests:
https://wpt.fyi/results/upgrade-insecure-requests/gen/iframe-blank-inherit.meta/unset/fetch.https.html?diff=&filter=ADC&run_id=5161602225799168&run_id=5177547862310912

@trflynn89 trflynn89 added bug Something isn't working has repro We have a way to reproduce this bug. labels Dec 12, 2024
@trflynn89 trflynn89 changed the title The fetch process hangs when a fetch completion promise invokes a second fetch via document.write The fetch process hangs when a microtask invokes fetch via document.write Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has repro We have a way to reproduce this bug.
Projects
None yet
Development

No branches or pull requests

1 participant