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

Rewrite node:http to not use Request & Response #14384

Draft
wants to merge 82 commits into
base: main
Choose a base branch
from
Draft

Conversation

Jarred-Sumner
Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner commented Oct 6, 2024

What does this PR do?

Extremely WIP.

Rewrite node:http to not use Request & Response for Bun.serve

Introduce a new internal API that currently looks like this and may change at any point:

import { serve } from "bun";

serve({
  port: 3002,

  onNodeHTTPRequest(server, url: string, method: string, headers: Record<string, string>, rawHeaders: string[], handle, hasBody: boolean) {
    handle.writeHead(200, { "Content-Type": "text/plain" });
    handle.end("Hello World");
  },
});

This does not replace fetch in Bun.serve()

How did you verify your code works?

it doesn't really work yet. We aren't emitting socket.

@robobun
Copy link

robobun commented Oct 6, 2024

@cirospaciari, your commit 249b8db has 21 failures in #6969:

  • test/js/bun/http/bun-serve-static.test.ts - timeout on 🐧 3.20 x64-baseline
  • test/regression/issue/09041.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/integration/next-pages/test/dev-server.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/integration/next-pages/test/dev-server.test.ts - 1 failing on 🐧 3.20 x64
  • test/cli/install/bun-run.test.ts - 1 failing on 🐧 3.20 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 12 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 12 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 22.04 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 22.04 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 aarch64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 x64-baseline
  • test/js/node/test/parallel/worker-nested-uncaught.test.js - segmentation fault on 🐧 3.20 aarch64
  • test/js/node/test/parallel/worker-nested-uncaught.test.js - segmentation fault on 🐧 3.20 x64-baseline
  • test/js/node/test/parallel/worker-nested-uncaught.test.js - segmentation fault on 🐧 3.20 x64
  • test/integration/next-pages/test/next-build.test.ts - 1 failing on 🐧 22.04 x64
  • test/integration/next-pages/test/next-build.test.ts - 1 failing on 🐧 22.04 x64-baseline
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 aarch64
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 x64
  • test/js/bun/http/serve.test.ts - segmentation fault on 🐧 3.20 aarch64
  • test/js/bun/http/serve.test.ts - segmentation fault on 🐧 3.20 x64
  • test/js/bun/http/serve.test.ts - segmentation fault on 🐧 3.20 x64-baseline
  • test/js/deno/performance/performance.test.ts - 1 failing on 🐧 22.04 x64
  • test/js/node/diagnostics_channel/diagnostics_channel.test.ts - 1 failing on 🐧 20.04 x64
  • test/js/node/test/parallel/timers-ordering.test.js - 1 failing on 🐧 22.04 aarch64
  • test/v8/v8.test.ts - 22 failing on 🪟 2019 x64
  • test/v8/v8.test.ts - 22 failing on 🪟 2019 x64-baseline
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 aarch64
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 x64-baseline
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 x64
  • test/js/node/test/parallel/http-client-timeout.test.js - timeout on 🪟 2019 x64-baseline
  • test/js/node/test/parallel/http-client-timeout.test.js - timeout on 🪟 2019 x64
  • test/js/node/http/node-http.test.ts - timeout on 🍎 14 aarch64
  • test/js/node/http/node-http.test.ts - timeout on 🍎 13 aarch64
  • test/js/node/http/node-http.test.ts - timeout on 🪟 2019 x64
  • test/js/node/http/node-http.test.ts - timeout on 🪟 2019 x64-baseline
  • test/js/node/http/node-http.test.ts - timeout on 🐧 20.04 aarch64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 11 aarch64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 22.04 aarch64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 12 aarch64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 12 x64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 11 x64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 20.04 x64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 22.04 x64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 20.04 x64-baseline
  • test/js/node/http/node-http.test.ts - timeout on 🐧 12 x64-baseline
  • test/js/node/http/node-http.test.ts - timeout on 🐧 11 x64-baseline
  • test/js/node/http/node-http.test.ts - timeout on 🐧 22.04 x64-baseline
  • test/js/node/http/node-http.test.ts - timeout on 🐧 3.20 aarch64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 3.20 x64
  • test/js/node/http/node-http.test.ts - timeout on 🐧 3.20 x64-baseline
  • test/js/node/http/node-http.test.ts - timeout on 🍎 13 x64
  • test/regression/issue/012040.test.ts - segmentation fault on 🪟 2019 x64-baseline
  • test/regression/issue/012040.test.ts - timeout on 🍎 14 aarch64
  • test/regression/issue/012040.test.ts - timeout on 🪟 2019 x64
  • test/regression/issue/012040.test.ts - timeout on 🍎 13 aarch64
  • test/regression/issue/012040.test.ts - timeout on 🐧 12 aarch64
  • test/regression/issue/012040.test.ts - timeout on 🐧 11 aarch64
  • test/regression/issue/012040.test.ts - timeout on 🐧 22.04 aarch64
  • test/regression/issue/012040.test.ts - timeout on 🐧 20.04 aarch64
  • test/regression/issue/012040.test.ts - timeout on 🐧 11 x64
  • test/regression/issue/012040.test.ts - timeout on 🐧 20.04 x64-baseline
  • test/regression/issue/012040.test.ts - timeout on 🐧 20.04 x64
  • test/regression/issue/012040.test.ts - timeout on 🐧 12 x64-baseline
  • test/regression/issue/012040.test.ts - timeout on 🐧 11 x64-baseline
  • test/regression/issue/012040.test.ts - timeout on 🐧 12 x64
  • test/regression/issue/012040.test.ts - timeout on 🐧 22.04 x64
  • test/regression/issue/012040.test.ts - timeout on 🐧 22.04 x64-baseline
  • test/regression/issue/012040.test.ts - timeout on 🐧 3.20 aarch64
  • test/regression/issue/012040.test.ts - timeout on 🐧 3.20 x64
  • test/regression/issue/012040.test.ts - timeout on 🐧 3.20 x64-baseline
  • test/regression/issue/012040.test.ts - timeout on 🍎 13 x64
  • test/cli/hot/hot.test.ts - timeout on 🪟 2019 x64-baseline
  • test/cli/hot/hot.test.ts - timeout on 🐧 3.20 x64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🪟 2019 x64-baseline
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🍎 14 aarch64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🍎 13 aarch64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🪟 2019 x64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 12 aarch64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 22.04 aarch64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 11 aarch64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 20.04 aarch64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 11 x64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 20.04 x64-baseline
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 12 x64-baseline
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 20.04 x64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 11 x64-baseline
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 12 x64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 22.04 x64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 22.04 x64-baseline
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 3.20 aarch64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 3.20 x64
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🐧 3.20 x64-baseline
  • test/js/node/test/parallel/http-outgoing-writablefinished.test.js - 1 failing on 🍎 13 x64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🪟 2019 x64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🪟 2019 x64-baseline
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🍎 14 aarch64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🍎 13 aarch64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 12 aarch64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 11 aarch64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 20.04 aarch64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 22.04 aarch64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 11 x64-baseline
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 12 x64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 12 x64-baseline
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 11 x64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 22.04 x64-baseline
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 20.04 x64-baseline
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 22.04 x64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 20.04 x64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 3.20 aarch64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 3.20 x64-baseline
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🐧 3.20 x64
  • test/js/node/test/parallel/http-outgoing-finish.test.js - 1 failing on 🍎 13 x64
  • test/js/first_party/ws/ws.test.ts - segmentation fault on 🪟 2019 x64-baseline
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x910003fda9bf7c05 on 🍎 13 aarch64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x910003fda9bf7c05 on 🍎 14 aarch64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x3fda9bf7c3d on 🐧 22.04 aarch64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x3fda9bf7c3d on 🐧 11 aarch64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x3fda9bf7c3d on 🐧 12 aarch64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x3fda9bf7c3d on 🐧 20.04 aarch64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 12 x64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 11 x64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 12 x64-baseline
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 20.04 x64-baseline
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 22.04 x64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 22.04 x64-baseline
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 11 x64-baseline
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 20.04 x64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x3fda9bf7c3d on 🐧 3.20 aarch64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 3.20 x64
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🐧 3.20 x64-baseline
  • test/js/first_party/ws/ws.test.ts - segmentation fault at address 0x0 on 🍎 13 x64
  • test/cli/run/require-cache.test.ts - 1 failing on 🪟 2019 x64
  • @kravetsone
    Copy link

    will it be available for the first time through the flag? it sounds dangerous if suddenly the insides change so much

    @Jarred-Sumner
    Copy link
    Collaborator Author

    @kravetsone i agree dangerous, but we have far better test coverage than we used to.

    @kravetsone
    Copy link

    @kravetsone i agree dangerous, but we have far better test coverage than we used to.

    It's great
    But it maybe more painful for developers which don't pin bun docker image version

    Test coverage can't find all bugs

    @Jarred-Sumner Jarred-Sumner mentioned this pull request Oct 7, 2024
    52 tasks
    @huseeiin
    Copy link
    Contributor

    huseeiin commented Oct 9, 2024

    super cool

    @huseeiin
    Copy link
    Contributor

    there was a trick in bun to get the Request object (from a symbol) in node:http:

    import { createServer } from "http";
    
    createServer(async (req, res) => {
        const request: Request = req[Object.getOwnPropertySymbols(req)[3]];
    
        const json = await request.json().catch(() => null);
    
        res.end(json);
    }).listen(3000);

    does this PR mean this is no longer gonna be possible?

    @cirospaciari cirospaciari self-assigned this Nov 13, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    8 participants