Skip to content

Bun hangs on a closed express server, Node.js works #19563

@mindreframer

Description

@mindreframer

What version of Bun is running?

1.2.12+32a47ae45

What platform is your computer?

Darwin 24.3.0 arm64 arm

What steps can reproduce the bug?

$ bun check.js

const request = require("supertest");
const express = require("express");

const app = express();

app.get("/user", function (req, res) {
  res.status(200).json({ name: "john" });
});

const server = app.listen(); // Store server instance

request(app)
  .get("/user")
  .expect("Content-Type", /json/)
  .expect("Content-Length", "15")
  .expect(200)
  .end(function (err, res) {
    if (err) throw err;
    server.close(); // Close the server when done
  });

console.log("done");

What is the expected behavior?

The express server should be closed when reaching the end of the file, which works correctly in Node.js

What do you see instead?

The script hangs, not finishing properly.
process.exit(); is harder and kills the script for sure, but it should work by closing the server instance.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnice-reproAn unusually helpful reproduction is providednode:http

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions