uNetworking / uNetworking/uWebSockets
Invoking `endWithoutBody` with a size, without invoking `onAborted` is forbidden
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 19k
- Forks
- 1.9k
- Avg merge
- 3h 24m
- Merged PRs (30d)
- 5
Description
I tried to create a simple HTTP server that uses endWithoutBody with a size argument to handle HEAD requests, but it crashes with the following error message:
Error: Returning from a request handler without responding or attaching an abort handler is forbidden!
terminate called without an active exception
Aborted
Code:
import uWebSockets from "uWebSockets.js";
const buffer = Buffer.from("Test", "utf-8");
const server = uWebSockets.App().any("/*", (res, req) => {
const path = req.getUrl();
const method = req.getCaseSensitiveMethod();
if (path === "/test") {
res.writeStatus("200")
.writeHeader("Content-Type", "text/plain")
.writeHeader("Content-Length", String(buffer.length));
if (method === "HEAD") {
res.endWithoutBody(buffer.length);
return;
}
res.end(buffer);
return;
}
res.writeStatus("404").writeHeader("Content-Type", "text/plain").end("404 Not Found");
}).listen("127.0.0.1", 8888, () => {
});
When the res.endWithoutBody call is replaced with a res.end call with no arguments, this error does not occur. This behavior should be corrected because everything in the code is done synchronously, so there is no reason why the endWithoutBody behavior can't match the other, which sends a buffer and potentially requires more processing time.
If this is the intended behavior due to other considerations, it should at least be mentioned in the documentation or generate a warning message as the other functions do.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the uWebSockets.js request-handling entry points for res.endWithoutBody(size) and res.end(buffer), using the provided synchronous HEAD example to reproduce the abort error. Compare their request-lifecycle behavior and either make the synchronous call complete without the error or document the restriction and its warning behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100