cloudflare / cloudflare/workerd
Awaiting transform of empty response never resolves
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
Not sure if this is the best place to raise. We are using `HTMLRewriter` in a Cloudflare and encountered an issue which was difficult to track down.
The issue appears to be that `HTMLRewriter` when called with a response that has no body returns a new response but the methods to resolve the new response body never appear to resolve. Instead they cause the worker to exception with "... your Worker's code had hung and would never generate a response."
The below shows a simple reproduction example:
```
export default {
async fetch(request, env, ctx): Promise {
const rewriter = new HTMLRewriter();
rewriter.on('div', {
element: (el) => {
el.setInnerContent('rewritten content');
}
});
// Never resolves, causes:
// The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response.
// Refer to: https://developers.cloudflare.com/workers/observability/errors/
const rewrittenResponse = await rewriter.transform(new Response('')).text();
// Resolves
const rewrittenResponse = await rewriter.transform(new Response('
return new Response(rewrittenResponse, {
headers: {
'content-type': 'text/html'
}
});
},
} satisfies ExportedHandler;
```
It feels like it would be more consistent for await'ing to resolve with empty content or at least throwing in some way so the cause of the error is clearer.
Contributor guide
Assessment
This issue has not been assessed yet.