Skip to content

100% CPU usage after HTTPS fetch requests in node:http server (SSL connection pooling bug) #25430

@hamidrezahanafi

Description

@hamidrezahanafi

What version of Bun is running?

1.3.4

What platform is your computer?

Darwin 25.1.0 arm64 arm

What steps can reproduce the bug?

When using node:http to create an HTTP server that makes outbound HTTPS fetch() requests, CPU usage spikes to 100% and stays there indefinitely after requests complete.
Root cause: SSL socket connection pooling causes pooled sockets to continuously report as "readable" to the event loop (kevent64/epoll), even when there's no application data. This results in busy-polling.
Affected versions: Bun 1.3.4 (likely affects earlier versions too)
Platform: macOS (darwin), likely also Linux
Impact: Production servers become unresponsive, high resource usage, potential crashes.

// cpu-bug-repro.js
// Run with: bun cpu-bug-repro.js
// Then in another terminal: curl http://localhost:3456/
// Watch CPU: top -pid $(pgrep -f cpu-bug-repro)

const http = require("node:http");

const server = http.createServer(async (req, res) => {
  console.log(`${new Date().toISOString()} - ${req.method} ${req.url}`);
  
  if (req.url === "/") {
    // Make HTTPS fetch requests - triggers SSL connection pooling
    const results = await Promise.all([
      fetch("https://jsonplaceholder.typicode.com/posts/1").then(r => r.json()).catch(() => ({})),
      fetch("https://jsonplaceholder.typicode.com/posts/2").then(r => r.json()).catch(() => ({})),
      fetch("https://jsonplaceholder.typicode.com/users/1").then(r => r.json()).catch(() => ({})),
      fetch("https://api.github.com/repos/oven-sh/bun", {
        headers: { "User-Agent": "bun-test" }
      }).then(r => r.json()).catch(() => ({})),
    ]);
    
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify({ fetched: results.length }));
  } else {
    res.writeHead(404);
    res.end();
  }
});

server.listen(3456, () => {
  console.log(`
=======================================================
  Bun 100% CPU Bug Reproduction
=======================================================
  Server: http://localhost:3456
  Bun version: ${Bun.version}
  
  Steps:
    1. curl http://localhost:3456/
    2. Watch CPU: top -pid $(pgrep -f cpu-bug-repro)
  
  Expected: CPU returns to ~0% after request
  Actual: CPU stays at 100% indefinitely
=======================================================
`);
});

then on another terminal

bun cpu-bug-repro.js

for i in {1..10}; do curl -s http://localhost:3456/ & done; wait

Watch the CPU stays at 100%

What is the expected behavior?

CPU should go back to idle 0%

What do you see instead?

CPU stays at 100%

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions