-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Segmentation Fault Crash when using Prisma #7864
Comments
sorry to any contributors: without seeing the stack trace, my guess is it's an async context thing. Prisma uses async hooks + napi. Sharp & Prisma uses threadsafe functions. Threadsafe functions sometimes attempt to read from hooks. It's possible something is going wrong there. Another thought: maybe it's because we don't implement escapable handle scopes and the inner function is async. This would be reproducible for any async NAPI function (which is truly async, not just microtasks). Something like |
is there documentation for getting a stack trace for these segfaults? i'm running into this issue as well and would like to help if i can |
I also experienced this issue without any clues. What I can do now to keep my service running is to use bun v1.0.18 |
I can confirm this bug still present on latest bun 1.0.23 |
This bug still exists on |
I can confirm I was seeing this in bun v1.0.26. Downgrading to v1.0.18 with the following command (on Linux) seems to have made the problem go away for now...
|
I upgraded from bun v1.0.0 to v1.0.26 and I started getting this error intermittently when starting my server. Not using prisma. My server code has the following dependencies:
|
Something must gone very wrong in 1.0.19 upwards. I really want to dig it deeper, but... yeah... |
1.0.27 released, yay! Still error, but It is throwing different message than previous versions!!
EDIT: After I ran it several times, it throws usual segmentation fault. Back to 1.0.18 i guess... |
This is the same error I was getting in 1.0.26 as well when running |
Repro repo is here: https://github.com/camero2734/prisma-bun-issue (run w/ With
With
The repro code is: import { createCanvas } from "@napi-rs/canvas";
import { PrismaClient } from '@prisma/client';
const client = new PrismaClient();
async function causeError() {
// 1. Some DB query
const tx = client.$executeRaw`SELECT pg_sleep(0.01)`;
// 2. Some napi-based operation
createCanvas(1000, 1000);
// 3. Wait for the DB query to finish
await tx;
}
let success = true;
for (let i = 0; i < 50; i++) {
try {
await causeError();
} catch (e) {
console.error(e);
console.log(`Encountered error after ${i + 1} iterations`);
success = false;
break;
}
}
if (success) console.log("No error"); If I remove Edit: Also found that the problem is gone if I build |
Okay, I've narrowed down that set of changes to just a single line in // src/bun.js/bindings/napi.cpp
extern "C" napi_status napi_delete_reference(napi_env env, napi_ref ref)
{
NAPI_PREMABLE
NapiRef* napiRef = toJS(ref);
napiRef->~NapiRef(); // PREVIOUS -- reverting to this fixes the issues with Prisma
delete napiRef // CURRENT -- breaks Prisma
return napi_ok;
} |
Pinging @Jarred-Sumner, can we just revert this line to solve this issue ? |
* Add test for #7864 * Add napi-rs/canvas --------- Co-authored-by: Jarred Sumner <[email protected]>
What version of Bun is running?
1.0.20+09d51486e
What platform is your computer?
Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
What is the expected behavior?
The insertion should happen normally.
What do you see instead?
error: script was terminated by signal SIGSEGV (Address boundary error)
Segmentation fault
Additional information
We tried to transform an image through
sharp
and store the S3 path to where they were uploaded.We refactored the functions so that the transformation happens in another method. The transformations and uploads would happen normally, but during Prisma insertion, the script crashes directly.
This works on 1.0.15, but not since.
Output from
bunx prisma -v
:The text was updated successfully, but these errors were encountered: