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

std/http throws on large chunked responses #6263

Closed
sholladay opened this issue Jun 12, 2020 · 1 comment · Fixed by #6269
Closed

std/http throws on large chunked responses #6263

sholladay opened this issue Jun 12, 2020 · 1 comment · Fixed by #6269
Labels
bug Something isn't working

Comments

@sholladay
Copy link

sholladay commented Jun 12, 2020

The chunked response handling in std/http seems to be very broken. When you give it a Reader, it's supposed to send a chunked response, but it throws an error after only a few megabytes of data.

Below is a script to reproduce this. If image.jpg is very small, it'll work fine. Interestingly, the amount of data that actually gets sent to the client seems to be somewhat erratic. Sometimes I get ~4 megabytes, sometimes I get < 2 megabytes. Maybe backpressure isn't working properly?

import * as http from 'https://deno.land/std@v0.56.0/http/server.ts';

const respond = async (request: http.ServerRequest) => {
    const file = await Deno.open('./image.jpg');
    await request.respond({
        body   : file,  // works if file is very small, but throws an error if it's a bit large (>4MB ???)
        status : 200
    });
    file.close();
};

for await (const request of http.serve({ port : 3000 })) {
    respond(request);
}

Stack trace

error: Uncaught Error: Short write
      this.err = new Error("Short write");
                 ^
    at BufWriter.checkBytesWritten (https://deno.land/std@v0.56.0/io/bufio.ts:436:18)
    at BufWriter.flush (https://deno.land/std@v0.56.0/io/bufio.ts:487:10)
    at async BufWriter.write (https://deno.land/std@v0.56.0/io/bufio.ts:518:9)
    at async writeChunkedBody (https://deno.land/std@v0.56.0/http/_io.ts:171:5)
    at async writeResponse (https://deno.land/std@v0.56.0/http/_io.ts:267:5)
    at async ServerRequest.respond (https://deno.land/std@v0.56.0/http/server.ts:88:7)
    at async respond (file:///Users/sholladay/Code/personal/pogo/server.ts:5:5)

Environment

OS: macOS 10.14.6

$ deno --version
deno 1.0.2
v8 8.4.300
typescript 3.9.2

I am also able to reproduce this on Deno 1.0.5.

@marcosc90
Copy link
Contributor

marcosc90 commented Jun 12, 2020

Can you try updating to 1.1.0?

Can't reproduce on Can reproduce after spamming multiple requests on:

Ubuntu 20.04
deno 1.1.0
v8 8.4.300
typescript 3.9.2

I'm working on a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants