1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00
denoland-deno/ext
Matt Mastracci 431289faaa fix(ext/http): ensure request body resource lives as long as response is alive (#20206)
Deno.serve's fast streaming implementation was not keeping the request
body resource ID alive. We were taking the `Rc<Resource>` from the
resource table during the response, so a hairpin duplex response that
fed back the request body would work.

However, if any JS code attempted to read from the request body (which
requires the resource ID to be valid), the response would fail with a
difficult-to-diagnose "EOF" error.

This was affecting more complex duplex uses of `Deno.fetch` (though as
far as I can tell was unreported).

Simple test:

```ts
        const reader = request.body.getReader();
        return new Response(
          new ReadableStream({
            async pull(controller) {
              const { done, value } = await reader.read();
              if (done) {
                controller.close();
              } else {
                controller.enqueue(value);
              }
            },
          }),
```

And then attempt to use the stream in duplex mode:

```ts

async function testDuplex(
  reader: ReadableStreamDefaultReader<Uint8Array>,
  writable: WritableStreamDefaultWriter<Uint8Array>,
) {
  await writable.write(new Uint8Array([1]));
  const chunk1 = await reader.read();
  assert(!chunk1.done);
  assertEquals(chunk1.value, new Uint8Array([1]));
  await writable.write(new Uint8Array([2]));
  const chunk2 = await reader.read();
  assert(!chunk2.done);
  assertEquals(chunk2.value, new Uint8Array([2]));
  await writable.close();
  const chunk3 = await reader.read();
  assert(chunk3.done);
}
```

In older versions of Deno, this would just lock up. I believe after
23ff0e722e, it started throwing a more
explicit error:

```
httpServerStreamDuplexJavascript => ./cli/tests/unit/serve_test.ts:1339:6
error: TypeError: request or response body error: error reading a body from connection: Connection reset by peer (os error 54)
    at async Object.pull (ext:deno_web/06_streams.js:810:27)
```
2023-08-21 18:23:28 +05:30
..
broadcast_channel 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
cache 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
console 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
crypto 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
fetch fix: release ReadeableStream in fetch (#17365) 2023-08-21 18:23:27 +05:30
ffi 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
fs 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
http fix(ext/http): ensure request body resource lives as long as response is alive (#20206) 2023-08-21 18:23:28 +05:30
io chore: deno_core -> 0.201.0 (#20135) 2023-08-21 18:23:27 +05:30
kv feat(ext/kv): key expiration (#20091) 2023-08-21 18:23:27 +05:30
napi 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
net fix(ext/net): implement a graceful error on an invalid SSL certificate (#20157) 2023-08-21 18:23:27 +05:30
node fix(node/http): emit error when addr in use (#20200) 2023-08-21 18:23:27 +05:30
tls 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
url perf(ext/urlpattern): optimize URLPattern.exec (#20170) 2023-08-21 18:23:27 +05:30
web perf(ext/event): always set timeStamp to 0 (#20191) 2023-08-21 18:23:28 +05:30
webidl 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
websocket perf(ext/event): always set timeStamp to 0 (#20191) 2023-08-21 18:23:28 +05:30
webstorage 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30