deno_std: Error "Cannot read property 'w' of null at iterateHttpRequests" on aborted connections
// server.ts
import { serve } from "https://deno.land/std/http/server.ts";
async function main() {
for await (let req of serve(":80")) {
req.respond({});
}
}
main();
$ deno run --allow-net server.ts
/Users/<redacted>/Library/Caches/deno/deps/https/raw.githubusercontent.com/denoland/deno_std/master/http/server.ts:225:36
await writeResponse(req.w, {
^
Uncaught TypeError: Cannot read property 'w' of null
at iterateHttpRequests (file:///Users/<redacted>/Library/Caches/deno/deps/https/raw.githubusercontent.com/denoland/deno_std/master/http/server.ts:254:31)
$ autocannon localhost
Running 10s test @ localhost
10 connections
┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬──────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼──────────┤
│ Latency │ 0 ms │ 0 ms │ 1 ms │ 2 ms │ 0.07 ms │ 0.39 ms │ 11.05 ms │
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴──────────┘
┌───────────┬────────┬────────┬─────────┬─────────┬──────────┬─────────┬────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼────────┼────────┼─────────┼─────────┼──────────┼─────────┼────────┤
│ Req/Sec │ 22879 │ 22879 │ 27695 │ 28287 │ 27145.46 │ 1494.03 │ 22871 │
├───────────┼────────┼────────┼─────────┼─────────┼──────────┼─────────┼────────┤
│ Bytes/Sec │ 869 kB │ 869 kB │ 1.05 MB │ 1.08 MB │ 1.03 MB │ 56.8 kB │ 869 kB │
└───────────┴────────┴────────┴─────────┴─────────┴──────────┴─────────┴────────┘
Req/Bytes counts sampled once per second.
299k requests in 11.06s, 11.3 MB read
When I restarted the server and ran another load test, it crashed again. Might not be related to the high load, though.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (16 by maintainers)
On a side note, having the HTTP server in the std lib makes it surprisingly easy to debug. ❤️
Here’s a reliable reproduction:
Cloned
deno_std
and added a good old console log…The
req
variable which isnull
comes from[req, bufStateErr] = await readRequest(bufr);
. InreadRequest
there’s anif (err) { return [null, err]; }
block. So in this case, it is guaranteed that, if there is anerr
inreadRequest
, thereq
isnull
. Theerr
fromreadRequest
in this case is for the case that the HTTP status line can’t be read, I assume because the underlying connection has been closed.Not sure how to continue with this. Hope my investigation so far is helpful.