oven-sh / bun

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

SIGSEGV running a bun test that makes db calls #3200

Closed stephenh closed 2 months ago

stephenh commented 1 year ago

What version of Bun is running?

0.6.7

What platform is your computer?

Linux 5.19.0-42-generic x86_64 x86_64

What steps can reproduce the bug?

What is the expected behavior?

The test runs.

What do you see instead?

A seg fault:

$ bun test src/entities/Author.test.ts
bun test v0.6.7 (59d7c47e)
[0.02ms] ".env"

src/entities/Author.test.ts:
fish: Job 1, 'bun test src/entities/Author.te…' terminated by signal SIGSEGV (Address boundary error)

Additional information

Joist is a admittedly a niche ORM, but it uses pretty vanilla knex / node-pg to make db queries, so when I saw Prisma works in 0.6.7, I thought I'd try it out with Joist.

Jarred-Sumner commented 1 year ago

Probably a .env loader crash. Really need to fix that. Are there Windows newlines or trailing spaces in the .env file?

stephenh commented 1 year ago

@Jarred-Sumner I don't think it's the env loader, b/c if I run a different test, it goes further:

 $ bun test src/entities/Book.test.ts
bun test v0.6.7 (59d7c47e)
[0.02ms] ".env"

src/entities/Book.test.ts:
✓ Book > non-null reference might still have a null id [2.28ms]
✓ Book > should have default values populated immediately on create if they aren't provided as opts [0.44ms]
[bun] Warning: async_hooks has not been implemented yet. See https://github.com/oven-sh/bun/issues/1832
✓ Book > can update without the order field causing syntax errors [29.06ms]

It hangs there, which is the 1st time it would make a db call (the first two tests in Book.test.ts don't actually make db tests).

Per the async_hooks warning, I've technically imported the module, but commented out the code we use that actually relies on it (reads from it). ...well...shoot, maybe not all the code. Let me try making sure that is all gone; apologies if that ends up being it, as I knew that was not supported yet.

Jarred-Sumner commented 1 year ago

Memory issues are very mysterious sometimes. If you delete the .env file and manually set the env vars, does it still segfault?

stephenh commented 1 year ago

Sure, I've removed the .env file, set the only variable (DATABASE_URL) manually in fish, and the same seg fault still happens.

I also fully removed the AsyncLocalStorage import/code, and same behavior: Author.test.ts seg faults, and Book.test.ts hangs, although looks like it only hangs after doing all of the expected db calls, according to the knex output, which is good! (I'd assumed it was hanging on its initial db call.)

Jarred-Sumner commented 1 year ago

Alright, probably a bug in Bun.connect (which internally is used by node:net). @cirospaciari can you take a look when you get a chance?

cirospaciari commented 1 year ago

Alright, probably a bug in Bun.connect (which internally is used by node:net). @cirospaciari can you take a look when you get a chance?

Sure! Will take a look on this

eber404 commented 1 year ago

I got the same error using pino-pretty, so I just removed it from the project, and the error has gone.

cirospaciari commented 2 months ago

Looks like this is not happening any more in the current canary if is happening after bun upgrade --canary feel free to reopen