oven-sh / bun

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

100% CPU usage by epoll_wait in IO Watcher thread #8157

Open uxmaster opened 10 months ago

uxmaster commented 10 months ago

What version of Bun is running?

1.0.27

What platform is your computer?

Linux 5.15.0-91-generic x86_64 x86_64

What steps can reproduce the bug?

A request made to the Bun HTTP server (handled asynchronously and executing a statement in MySQL through mysql2).

What is the expected behavior?

CPU usage should return to 0 after the request.

What do you see instead?

CPU usage stays at 100% (IO Watcher thread).

Additional information

strace: Process 989744 detached
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00    5.174131      147832        35           epoll_wait
  0.00    0.000108           3        35           read
  0.00    0.000058           1        36           timerfd_settime
  0.00    0.000037           1        36        36 epoll_ctl
------ ----------- ----------- --------- --------- ----------------
100.00    5.174334                   142        36 total

It seems that version 1.0.19 introduced this bug, since up to 1.0.18 everything is OK.

Also, this is machine dependent. It's failing on DigitalOcean regular 1vCPU droplet in nyc1, while it runs OK on Vultr's High Frequency 1vCPU virtual machine in Chicago (same OS and kernel).

Jarred-Sumner commented 10 months ago

Can you paste code that reproduces this? This isn't enough information

uxmaster commented 10 months ago

Here goes the code:

import mysql2 from 'mysql2/promise';

const mysql = mysql2.createPool({
    socketPath: '/var/run/mysqld/mysqld.sock',
    user: 'user',
    password: 'password',
});

Bun.serve({
    async fetch(req) {
        await mysql.execute('SELECT 1');
        return new Response('Bun!');
    },
});

And:

curl http://localhost:3000
uxmaster commented 9 months ago

@Jarred-Sumner I pasted the code. What else can I do to help debug this bug?

This is affecting one of our production servers, so it's kind of important for me to fix it.

uxmaster commented 9 months ago

Oddly enough adding

await mysql.query('SELECT 2');

before

Bun.serve({
...

fixes the problem.

github-actions[bot] commented 3 months ago

This issue is stale and may be closed due to inactivity. If you're still running into this, please leave a comment.