oven-sh / bun

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

Bun stucks when I use the HTTP_X_SCHEME header #8446

Closed sirenkovladd closed 7 months ago

sirenkovladd commented 8 months ago

What version of Bun is running?

1.0.25+a8ff7be64

What platform is your computer?

Darwin 23.1.0 arm64 arm

What steps can reproduce the bug?

const { createServer, request } = require('http');

const server = createServer((req, res) => {
  console.log('http', req.url, JSON.stringify(req.headers));
  res.end('ok');
});

server.listen({ port: 0 }, () => {
  const { port } = server.address();
  console.log('port', port);

  const req = request({
    port,
    method: 'POST',
    headers: {
      connection: 'close',
      http_x_scheme: 'http',
    },
  });

  req.on('error', (err) => {
    console.log('err', err);
  });

  req.on('response', (res) => {
    console.log('recieve');
    res.on('data', (chunk) => {
      console.log('data', chunk.toString());
    });
    res.on('end', () => {
      server.close();
    });
  });

  console.log('send');
  req.end();
});

What is the expected behavior?

❯ node tt.js 
port 52503
send
http / {"connection":"close","http_x_scheme":"http","host":"localhost:52503","content-length":"0"}
recieve
data ok

What do you see instead?

❯ bun tt.js 
port 52588
send
err ConnectionClosed: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()
 path: "http://localhost:52588/"

Additional information

No response

sirenkovladd commented 8 months ago

The error is precisely in uws

when calling curl -X POST localhost:63453 -H "qwe:qwe" I see that https://github.com/oven-sh/bun/blob/bun-v1.0.25/packages/bun-uws/src/HttpContext.h#L473 is called

and with curl -X POST localhost:63453 -H "http_x_scheme:http" no longer

Maybe @Jarred-Sumner will have more ideas

sirenkovladd commented 7 months ago

Fixed in https://github.com/oven-sh/bun/pull/8830