oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.27k stars 2.77k forks source link

`node:http` IncomingMessage stream data cannot be read, events are not emitted #4733

Open cfal opened 1 year ago

cfal commented 1 year ago

What version of Bun is running?

1.0

What platform is your computer?

Linux x86_64

What steps can reproduce the bug?

import fs from 'fs';
import http from 'http';

var server = http.createServer(function(req, res) {
  if (req.method !== 'POST') {
    return res.writeHead(404).end();
  }
  const out = fs.createWriteStream('/tmp/output');
  req.pipe(out, { end: true });

  req.once('end', () => {
    console.log('request ended!');
  });

  req.once('close', () => {
    console.log('request closed!');
  });

  out.on('close', () => {
    console.log('file closed!');
  });

  res.statusCode = 200;  // status 200 OK
  res.setHeader('Content-Type', 'text/plain');  //response type
  res.end('Hello World\n');  //response body
});

server.listen(3000, '127.0.0.1', function() {
  // callback function to be called when the server starts listening
  console.log('Server running at http://127.0.0.1:3000/');
});

in a separate tab, POSt some data:

$ curl -v --data "testing" 127.0.0.1:3000
$ node httpserve.js
Server running at http://127.0.0.1:3000/
request ended!
request closed!
file closed!
$ cat /tmp/output
testing%
$
$ bun httpserve.js
Server running at http://127.0.0.1:3000/ 
$ cat /tmp/output
$

What is the expected behavior?

What do you see instead?

No response

Additional information

IncomingMessage._read doesn't seem to be implemented correctly https://github.com/oven-sh/bun/blob/07c8843/src/js/node/http.ts#L666

bnussman commented 1 year ago

I think I'm running into issues along these lines when using graphql-upload-minimal

liz3 commented 1 year ago

The IncomingMessage api does need a lot of work, maybe when i have more free time i can tackle the bigger task of implementing the entire IncomingMessage api and its sub apis, currently i don't have time for it. so depending on the urgency another contrbutor or maintainer needs to take care of it.