prisma: Segmentation fault crash when using prisma client when using PostgreSQL

Bug description

When trying to use findMany() (or any other method) on a model, prisma client crashes and the following line appears in my log: Segmentation fault (core dumped).

This only happens if I use PostgreSQL as far as I know, this first appeared when I switched to PostgreSQL from mysql.

How to reproduce

  1. Initiate a new prisma project (make sure to use PostgreSQL) and generate the client - no errors there
  2. Write a simple client which fetches some data from the databse
  3. The script crashes and Segmentation fault (core dumped) gets logged in the console

Expected behavior

The script does not crash.

Prisma information

Example schema:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
    id String @id
    email String?
}

Example test client:

const {PrismaClient} = require('@prisma/client');
const prisma = new PrismaClient({ log: ['query', 'info', 'warn'] })
prisma.user.findMany().then((e) => {
    console.log(e)
})

Environment & setup

  • OS: Pop!_OS (Linux pop-os 5.15.5-76051505-generic #202111250933~1638201579~21.04~09f1aa7-Ubuntu SMP Tue Nov 30 02: x86_64 x86_64 x86_64 GNU/Linux)
  • Database: PostgreSQL v14.1 (Ubuntu 14.1-1.pgdg21.04+1)
  • Node.js version: v17.2.0

Prisma Version

prisma                  : 3.6.0
@prisma/client          : 3.6.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : dc520b92b1ebb2d28dc3161f9f82e875bd35d727
Studio                  : 0.440.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 47
  • Comments: 113 (34 by maintainers)

Commits related to this issue

Most upvoted comments

While we are looking for the best way to fix or prevent the underlying problem, the recommended workaround for affected users is to make sure that the versions of OpenSSL used by Node.js and the system OpenSSL match:

  • either by downgrading Node.js to 16.x,
  • or by upgrading the operating system (or Docker image) to use OpenSSL 3 (for example, by using Ubuntu 22.04 instead of Debian 11). Depending on your requirements, it might be less suitable for production systems, but this is a good option for those who only encounter the issue on their local machines during development.

If your distribution provides a build of Node.js 18 with OpenSSL 1.1.1, you can use that instead of the upstream Node.js build that vendors OpenSSL 3. This is the case on Alpine, where you can install nodejs-current from repository community: it provides (at the moment of writing) Node.js 18.6.0 linked with OpenSSL 1.1.1q, and the issue is not reproducible when using it.

Alternatively, if you can’t do any of that and you need to stay with the upstream build of Node.js 18 on a system with OpenSSL 1.1.x, you can switch to the binary engine in Prisma.

Reproduction

  1. Create a cloud PostgreSQL database. I used Amazon RDS PostgreSQL 14.3 and Supabase.

  2. Create a minimal Prisma project. I used the following (but it doesn’t matter — you can reuse whatever test project you have):

    generator client {
      provider = "prisma-client-js"
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    model User {
      id    Int    @id
      login String @unique
    }
    
    import { PrismaClient } from '@prisma/client'
    
    async function main() {
      const client = new PrismaClient()
    
      const results = await client.user.findMany()
      console.log(results)
    }
    
    void main()
    
  3. Run it on x86-64 Debian 11 with Node.js 17+.4.

  4. Process crashes with segmentation fault.

❗️Note: the segfault is not reproducible on the same Debian version with exact same versions of all packages when using Node.js 16 or on ARM64.

Run ulimit -c unlimited beforehand if necessary if you want to get the core dump.

Here’s the full backtrace with symbols: (click to expand)
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f5ca8a5c143 in SSL_get_peer_certificate () from /lib/x86_64-linux-gnu/libssl.so.1.1
[Current thread is 1 (Thread 0x7f5c987b2700 (LWP 1182))]
(gdb) bt
#0  0x00007f5ca8a5c143 in SSL_get_peer_certificate () from /lib/x86_64-linux-gnu/libssl.so.1.1
#1  0x00007f5c99c518e7 in openssl::ssl::SslRef::peer_certificate ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#2  0x00007f5c9982292d in native_tls::imp::TlsStream<S>::tls_server_end_point ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#3  0x00007f5c999a9b05 in <postgres_native_tls::TlsStream<S> as tokio_postgres::tls::TlsStream>::channel_binding ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#4  0x00007f5c999302f6 in <tokio_postgres::maybe_tls_stream::MaybeTlsStream<S,T> as tokio_postgres::tls::TlsStream>::channel_binding () from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#5  0x00007f5c99846d54 in tokio_postgres::connect_raw::connect_raw::{{closure}} ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#6  0x00007f5c998bd6e1 in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#7  0x00007f5c99996e7f in <tokio::time::timeout::Timeout<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#8  0x00007f5c998cfeef in <quaint::pooled::manager::QuaintManager as mobc::Manager>::connect::{{closure}} ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#9  0x00007f5c99886280 in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#10 0x00007f5c992bb06e in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#11 0x00007f5c992ad399 in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#12 0x00007f5c9923f9a5 in mobc::time::timeout::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h87d7ad478931b0ea ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#13 0x00007f5c992446a3 in <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#14 0x00007f5c992cb97f in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#15 0x00007f5c992c4643 in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#16 0x00007f5c992ac990 in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#17 0x00007f5c98cc572d in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#18 0x00007f5c98cfbf35 in <tracing::instrument::Instrumented<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#19 0x00007f5c98ca1535 in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#20 0x00007f5c98cb476d in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#21 0x00007f5c98c983c6 in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#22 0x00007f5c98c2534d in tokio::runtime::task::harness::poll_future ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#23 0x00007f5c98c2be3e in tokio::runtime::task::harness::Harness<T,S>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#24 0x00007f5c99c33025 in std::thread::local::LocalKey<T>::with ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#25 0x00007f5c99c23693 in tokio::runtime::thread_pool::worker::Context::run_task ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#26 0x00007f5c99c22b9e in tokio::runtime::thread_pool::worker::Context::run ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#27 0x00007f5c99c34ae7 in tokio::macros::scoped_tls::ScopedKey<T>::set ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#28 0x00007f5c99c225bb in tokio::runtime::thread_pool::worker::run ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
--Type <RET> for more, q to quit, c to continue without paging--
#29 0x00007f5c99c39d21 in <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#30 0x00007f5c99c44a29 in tokio::runtime::task::harness::Harness<T,S>::poll ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#31 0x00007f5c99c28e6a in tokio::runtime::blocking::pool::Inner::run ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#32 0x00007f5c99c37ac2 in std::sys_common::backtrace::__rust_begin_short_backtrace ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#33 0x00007f5c99c3b14f in core::ops::function::FnOnce::call_once{{vtable-shim}} ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#34 0x00007f5c99f028d3 in alloc::boxed::{impl#44}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> () at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/alloc/src/boxed.rs:1872
#35 alloc::boxed::{impl#44}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> ()
    at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/alloc/src/boxed.rs:1872
#36 std::sys::unix::thread::{impl#2}::new::thread_start () at library/std/src/sys/unix/thread.rs:108
#37 0x00007f5cab4c3ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#38 0x00007f5cab3e3aef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95k

And here’s the relevant part:

#0  0x00007f5ca8a5c143 in SSL_get_peer_certificate () from /lib/x86_64-linux-gnu/libssl.so.1.1
#1  0x00007f5c99c518e7 in openssl::ssl::SslRef::peer_certificate ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#2  0x00007f5c9982292d in native_tls::imp::TlsStream<S>::tls_server_end_point ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#3  0x00007f5c999a9b05 in <postgres_native_tls::TlsStream<S> as tokio_postgres::tls::TlsStream>::channel_binding ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#4  0x00007f5c999302f6 in <tokio_postgres::maybe_tls_stream::MaybeTlsStream<S,T> as tokio_postgres::tls::TlsStream>::channel_binding () from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#5  0x00007f5c99846d54 in tokio_postgres::connect_raw::connect_raw::{{closure}} ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#8  0x00007f5c998cfeef in <quaint::pooled::manager::QuaintManager as mobc::Manager>::connect::{{closure}} ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
#12 0x00007f5c9923f9a5 in mobc::time::timeout::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h87d7ad478931b0ea ()
   from /home/aqrln/repro/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node

Immediate Cause

Whether the issue is reproducible depends on Node.js version: on the same system the reproduction script succeeds on Node.js 16.17.0 and older, but crashes with segmentation fault on Node.js 17.0.0 or newer.

Git bisect shows that the specific commit in Node.js that starts failing is https://github.com/nodejs/node/commit/66da32c045035cf2710a48773dc6f55f00e20c40.

This means that somehow the issue is triggered due to Node.js itself using bundled OpenSSL 3.0 and us using system OpenSSL, which in this case is 1.1.1n.

The specific instruction where it crashes inside OpenSSL:

(gdb) p $rip
$1 = (void (*)()) 0x7f5ca8a5c143 <SSL_get_peer_certificate+19>
(gdb) disassemble
Dump of assembler code for function SSL_get_peer_certificate:
   0x00007f5ca8a5c130 <+0>:     push   %r12
   0x00007f5ca8a5c132 <+2>:     test   %rdi,%rdi
   0x00007f5ca8a5c135 <+5>:     je     0x7f5ca8a5c160 <SSL_get_peer_certificate+48>
   0x00007f5ca8a5c137 <+7>:     mov    0x510(%rdi),%r12
   0x00007f5ca8a5c13e <+14>:    test   %r12,%r12
   0x00007f5ca8a5c141 <+17>:    je     0x7f5ca8a5c158 <SSL_get_peer_certificate+40>
=> 0x00007f5ca8a5c143 <+19>:    mov    0x1b8(%r12),%r12
   0x00007f5ca8a5c14b <+27>:    test   %r12,%r12
   0x00007f5ca8a5c14e <+30>:    je     0x7f5ca8a5c158 <SSL_get_peer_certificate+40>
   0x00007f5ca8a5c150 <+32>:    mov    %r12,%rdi
   0x00007f5ca8a5c153 <+35>:    call   0x7f5ca8a423b0 <X509_up_ref@plt>
   0x00007f5ca8a5c158 <+40>:    mov    %r12,%rax
   0x00007f5ca8a5c15b <+43>:    pop    %r12
   0x00007f5ca8a5c15d <+45>:    ret
   0x00007f5ca8a5c15e <+46>:    xchg   %ax,%ax
   0x00007f5ca8a5c160 <+48>:    xor    %r12d,%r12d
   0x00007f5ca8a5c163 <+51>:    mov    %r12,%rax
   0x00007f5ca8a5c166 <+54>:    pop    %r12
   0x00007f5ca8a5c168 <+56>:    ret
End of assembler dump.

The source code of the function:

X509 *SSL_get_peer_certificate(const SSL *s)
{
    X509 *r;

    if ((s == NULL) || (s->session == NULL))
        r = NULL;
    else
        r = s->session->peer;

    if (r == NULL)
        return r;

    X509_up_ref(r);

    return r;
}

In other words, the segfault happens due to the ->peer access on the r = s->session->peer line.

Let’s check s->session value:

(gdb) p/x $r12
$8 = 0xffffffff

This indeed looks wrong: the value is oddly specific (looks like it came from some int that was equal to -1) and is definitely outside the heap (for comparison, s is 0x7f5c88003330).

Running this on ARM64 and putting a breakpoint there, you can see that the pointer looks normal, so it doesn’t just work “accidentally”, the bug indeed doesn’t occur on that platform.
(gdb) disassemble
Dump of assembler code for function SSL_get_peer_certificate:
   0x0000ffffe65f5bc8 <+0>:     stp     x29, x30, [sp, #-32]!
   0x0000ffffe65f5bcc <+4>:     mov     x29, sp
   0x0000ffffe65f5bd0 <+8>:     str     x19, [sp, #16]
   0x0000ffffe65f5bd4 <+12>:    cbz     x0, 0xffffe65f5c00 <SSL_get_peer_certificate+56>
   0x0000ffffe65f5bd8 <+16>:    ldr     x0, [x0, #1296]
   0x0000ffffe65f5bdc <+20>:    cbz     x0, 0xffffe65f5c00 <SSL_get_peer_certificate+56>
   0x0000ffffe65f5be0 <+24>:    ldr     x19, [x0, #440]
=> 0x0000ffffe65f5be4 <+28>:    cbz     x19, 0xffffe65f5bf0 <SSL_get_peer_certificate+40>
   0x0000ffffe65f5be8 <+32>:    mov     x0, x19
   0x0000ffffe65f5bec <+36>:    bl      0xffffe66c8f48 <X509_up_ref>
   0x0000ffffe65f5bf0 <+40>:    mov     x0, x19
   0x0000ffffe65f5bf4 <+44>:    ldr     x19, [sp, #16]
   0x0000ffffe65f5bf8 <+48>:    ldp     x29, x30, [sp], #32
   0x0000ffffe65f5bfc <+52>:    ret
   0x0000ffffe65f5c00 <+56>:    mov     x19, #0x0                       // #0
   0x0000ffffe65f5c04 <+60>:    b       0xffffe65f5bf0 <SSL_get_peer_certificate+40>
End of assembler dump.
(gdb) p/x $x0
$1 = 0xffffd40152c0
(gdb) p/x $x19
$2 = 0xffffd400f210

Duplicate issues

Internal document

https://www.notion.so/prismaio/Segmentation-fault-with-cloud-PostgreSQL-b1b34ba631c44e9e9031f0cf63bcb23f

I’m using Ubuntu, and I was able to make it work by downgrading to v16 of Node. But this needs to be fixed. The other thing that I tried, and it worked (with Node v18), was adding engineType = "binary" to schema.prisma and running npx prisma generate again.

generator client {
  provider   = "prisma-client-js"
  engineType = "binary" // add this
}

Add the same issue running on latest node version 17.4.0. Fixed by using the current LTS 16.3.2.

In my case, downgrading to node 16.17.0 (using node:16-bullseye) works. I did not change anything else!

This is only a short term solution though.

This issue is fixed in Prisma 4.13.0 which will be released tomorrow, on Tuesday, Apr 18. If you need to temporarily use a pre-release version until then, you can use 4.13.0-dev.33.

Note that this GitHub issue is about a specific bug that occurs when using Node.js 17+ on a system with OpenSSL 1.1 on x86-64 CPUs when using TLS to connect to database. Please do not post comments here if you encounter a segfault under different circumstances, and open a new issue instead!

If you are facing segfaults on ARM, please leave a comment in https://github.com/prisma/prisma/issues/18510 or open a new issue.

Hi everyone! Could you check if updating prisma and @prisma/client to 4.12.0-integration-rtld-deepbind.3 fixes the issue for you? It does in the cases that I tested, but it would be very helpful to test this on more different systems.

This is an experimental dev version not intended for production but if it works as expected, we’ll work on making this land in a stable release. Thank you!

I’ve spent many hours trying to figure out why Prisma is segfaulting in the query engine, have tried changing the engine format to “engine” but without any promising result unfortunately.

Prisma 5.0.0
Platform Dockerized through MacOS M1 (ARM)
NodeJS 18.17.0

I tried playing around with different versions and found that node 18.16 and above has this problem, from what I can tell node version 18.15 is the latest version that runs without encountering any segfault. Worth noting is that the faulty versions did still work for smaller queries but they broke when GraphQL concatenated larger queries which I had a test case for.

So basically this was the workaround I came up with:

# Dockerfile
FROM node:18 -> FROM node:18.15

@aqrln I tested this and it works:

(node 18, debian bullseye, hosted postgres DB, prisma 4.11.0) => error with segfault on connect

image

(node 18, debian bullseye, hosted postgres DB, prisma 4.12.0-integration-rtld-deepbind.3) => successful connection

image

@janpio Here are the steps to reproduce this. I used a fresh VM (Ubuntu 20.04 LTS) on Google Compute Engine. I used a fresh PostgreSQL database (try Supabase for a quick test).

npm init -y
npm install -D prisma
npm install @prisma/client
nano schema.prisma

schema.prisma:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = "URL"
}

model User {
  id             String       @id @default(uuid())
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
}
npx prisma generate
npx prisma studio

Now try and view a model on localhost:5555…

Prisma Studio frontend logs:

Prisma Client Error
Unable to run script
Message: Error in HTTP Request (Status: 502)
Query:
[object Object]

Console logs:

Prisma schema loaded from schema.prisma
Prisma Studio is up on http://localhost:5555
Segmentation fault (core dumped)

Error also seen with Ubuntu 18.04 LTS on Windows WSL2. I cannot reproduce this on my home setup (Arch Linux).

Error could not be fixed by changing engine to binary (cc @tisuela)

generator client {
  provider = "prisma-client-js"
  engineType = "binary"
}

To anyone else using linux-musl as their platform, upgrading prisma versions wasn’t enough for me. I also had to add engineType = "binary" to my client in the schema.prisma file

Just deployed my app first time yesterday. Had the exact same issue as described here, literally tried everything before finding this thread. Fixed it by downgrading node:18 in my Dockerfile to node:16.18.0

With node:18 going into active LTS 6 days ago, stuff will hit the fan in here real soon I believe 😂 Especially as this setup is super common: Prisma, Node 18, standard DigitalOcean Droplet

My setup was:

  • DB: PSQL on Supabase

  • Node: node:18 downgrade to node:16.18.0

  • NestJS

  • Prisma: ^3.15.2

  • Production: DigitalOcean droplet with image: Ubuntu Docker 19.03.12 on Ubuntu 20.04

  • Local: M1 MacBook (had to adapt Dockerfile and prisma.schema’s binaryTargets to make it work on M1, doesn’t affect prod)

I still don’t know what the issue could be, but I have followed this guide to debug this issue a little bit more. I have to admit, I don’t have any experience with this, but I have attached crash.log file which got generated by the segfault-handler module:

PID 19523 received SIGSEGV for address: 0x1000001b7
/home/simonc/workspace/prisma-test/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x372d)[0x7f92370cf72d]
/lib/x86_64-linux-gnu/libc.so.6(+0x46520)[0x7f9236bc4520]
/lib/x86_64-linux-gnu/libssl.so.1.1(SSL_get_peer_certificate+0x17)[0x7f92342e4d87]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1410427)[0x7f921565d427]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xf37b0d)[0x7f9215184b0d]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x10d8010)[0x7f9215325010]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xf7551e)[0x7f92151c251e]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xff5e62)[0x7f9215242e62]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xffdd3d)[0x7f921524ad3d]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xfd66cd)[0x7f92152236cd]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc4755d)[0x7f9214e9455d]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc6ce8b)[0x7f9214eb9e8b]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc7cd46)[0x7f9214ec9d46]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc0f64a)[0x7f9214e5c64a]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc18023)[0x7f9214e65023]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc5b5d8)[0x7f9214ea85d8]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc43c2a)[0x7f9214e90c2a]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc65e87)[0x7f9214eb2e87]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc629a4)[0x7f9214eaf9a4]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xc526a7)[0x7f9214e9f6a7]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x20a71a)[0x7f921445771a]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x20916b)[0x7f921445616b]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1b1529)[0x7f92143fe529]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13d23d6)[0x7f921561f3d6]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13d18e8)[0x7f921561e8e8]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13bfc65)[0x7f921560cc65]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13d0d2c)[0x7f921561dd2c]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13d669f)[0x7f921562369f]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13cac68)[0x7f9215617c68]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13c9926)[0x7f9215616926]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13be02a)[0x7f921560b02a]
/home/simonc/workspace/prisma-test/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x13d5f78)[0x7f9215622f78]

Maybe this helps

@aqrln This works for me as well!

Node 18, Ubuntu 20.04 on Windows (WSL2), hosted PostgreSQL database (on GCP)

prisma and @prisma/client version 4.9 => Segmentation Fault: image

prisma and @prisma/client version 4.12.0-integration-rtld-deepbind.3 => works perfectly!: image

I hope you get the PR merged soon!

I’m using version 3.15.1 of Prisma. The error also happens when I specify node:18.3.0-alpine. I’m using a Postgres database provided by Supabase.

I seem to be having similar problems with the node:18-alpine base image in Docker. I get the error <container name> exited with code 139, which indicates a segmentation fault, as soon as my application calls findMany.

node:16-alpine works. I’d like to use Node 18 if possible, though.

Not sure if this helps but I tried using Google Cloud SQL for PostgreSQL but having the same issues:

[218]: [1-1] db=postgres,user=postgres LOG:  could not receive data from client: Connection reset by peer

Error persists when using version 3.5.0 for prisma CLI and client:

Environment variables loaded from .env                                                                                  
Prisma schema loaded from schema.prisma                                                                                 
Prisma Studio is up on http://localhost:5555
┌─────────────────────────────────────────────────────────┐                                                             
│  Update available 3.5.0 -> 3.7.0                        
│                                                             
│  Run the following to update                            
│                                                             
│    npm i --save-dev prisma@latest                       
│                                                             
│    npm i @prisma/client@latest                          
│                                                             
└─────────────────────────────────────────────────────────┘                                                             
Segmentation fault

I just fixed this by using the binary engine instead of the library engine. Will there ever be a proper fix for this?

@aqrln Fixed here too 💯 same configuration as @mmachatschek

FWIW we are having the same issue.

This works fine locally Prisma: 4.2.0 Node: 18-slim Postgres (local which works fine): postgres:14.4-alpine

The same docker image that works locally vs a containerized postgres fails when deployed to ECS Fargate vs an RDS postgres db running 14.2 with the same segmentation fault experienced by others.

Found a solution that worked for me based on the info in this thread so I figured I should share.

I have been doing local development with no issues using docker for two months with no issues using the following versions: postgres: 14 node:18 prisma: 3.14.1

However, once i tried to deploy on AWS I got the segfault crash others in this thread were talking about. Our solution was to downgrade to use the following versions to get things working in AWS: Postgres: 13.4 node: 18 prisma: 4.1.0

Since there were no issue running the application in local containers, it seems like it is an issue with node version above 16 in combination with postgres 14 in cloud providers like AWS and GCP.

I’m having similar issue. But I can’t create a reproducible case, it only happens when running our whole application. I can only recreate it on ARM64 machine and not on AMD64 which is strange.

I have tried the new testing version, but it doesn’t fix my issue. More information can be found in the following slack thread https://prisma.slack.com/archives/CA491RJH0/p1679654874088859

Can someone facing this issue send us the core dump file? We would really like to look into this!

Just to add on here:

We are running in Cloud Run with Cloud SQL. We had a number of issues using the generally documented CloudSQL volume mounts to connect our Cloud Run instances to our database.

Switching to the IP address method in our DB Connection strings would cause our applications to segfault immediately.

The fix we found worked was to add sslmode=disable when using direct IP addresses in our connection strings, and that seems to have resolved our issues. Just in case this helps anyone else who is having issues with Prisma and CloudRun/CloudSQL.

We didn’t attempt any of the experiments above to change our binary type, or our nodejs version.

Downgrading the node version to 16 from 18 worked for me. It didn’t matter whether I set the engineType to binary or not. It worked in both cases. However, it didn’t work in node v18, even with binary engineType. I am using PopOs 22.04

I was having the same issue of segmentation fault, interesting thing was, I was able to access db using prisma studio but not with prisma client, solved it by downgrading to node v16 from v18

Getting segfaults as well with the new prisma version 4.10.1 - we’re running node:16.16-alpine3.16 - previously had to custom build an image using 4.8.1

If you’re trying to run this inside the standard node:18 docker image then it’s not enough to just do:

apt update && apt install -y openssl

because the system includes openssl@1.1.1 by default.

One way to get around this is to use node:18-alpine which does not come with openssl installed out of the box. Then you can run:

apk update && apk add openssl

This will make the system use openssl@3.x which will then mean that when the Prisma database client dynamically links to it, the right version is available. Et voila, no more segfault 😄

Seems like the real issue here is that the Prisma database engine binary and Node binary link to openssl in different ways which can cause version mismatches?

TLDR;

FROM node:18-alpine

RUN apk update && apk add openssl
# do your thing ...

FROM node:18

RUN apt update && apt install -y openssl
# do your thing...

Some additional details from newly added duplicate issues:

  1. In https://github.com/prisma/prisma/issues/13641 @maximm98 reported the issue on RHEL (Rocky Linux 8). They say for them the issue started happening only after upgrading from Node.js 18.1.0 to Node.js 18.3.0, but I can’t reproduce it working with 18.1.0 — for me it crashes too.

  2. In https://github.com/prisma/prisma/issues/15052#issuecomment-1239812483 @garth reported that the issue happens with PostgreSQL 14, but not with PostgreSQL 12. I haven’t try reproducing it, but it sounds like an interesting detail. Although it’s also possible that v12 was self-hosted and v14 is in cloud — the report doesn’t include that information.

Locally and in the CI, I am using postgres in a docker container

Thank you, this is very valuable information.

I would love to, but I did not get one 😦

No worries. Just don’t share it via public channels if you manage to get one later if it comes from the production environment — sorry if this is obvious, just wanted to point this out just in case.

I’ll try to reproduce it on Monday with the information we now have.

Hi, new to the party but having the same problem. Everything works locally and in our CI, but as soon as the code is deployed to AWS ECS (fargate), then it explodes in a fiery segfault 😃 I have a fresh dump of the trace for the segfault.

PID 20 received SIGSEGV for address: 0x1000001b7
/app/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x2e65)[0x7f28bb3e0e65]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f28bb09c140]
/usr/lib/x86_64-linux-gnu/libssl.so.1.1(SSL_get_peer_certificate+0x13)[0x7f28b80ee143]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x11aa8e7)[0x7f28a34548e7]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xd7b92d)[0x7f28a302592d]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xf02b05)[0x7f28a31acb05]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xe892f6)[0x7f28a31332f6]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xd9fd54)[0x7f28a3049d54]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xe166e1)[0x7f28a30c06e1]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xeefe7f)[0x7f28a3199e7f]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xe28eef)[0x7f28a30d2eef]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xddf280)[0x7f28a3089280]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x81406e)[0x7f28a2abe06e]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x806399)[0x7f28a2ab0399]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x7989a5)[0x7f28a2a429a5]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x79d6a3)[0x7f28a2a476a3]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x82497f)[0x7f28a2ace97f]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x81d643)[0x7f28a2ac7643]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x805990)[0x7f28a2aaf990]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x21e72d)[0x7f28a24c872d]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x254f35)[0x7f28a24fef35]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1fa535)[0x7f28a24a4535]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x20d76d)[0x7f28a24b776d]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1f13c6)[0x7f28a249b3c6]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x17e34d)[0x7f28a242834d]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x184e3e)[0x7f28a242ee3e]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x118c025)[0x7f28a3436025]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x117c693)[0x7f28a3426693]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x117bb9e)[0x7f28a3425b9e]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x118dae7)[0x7f28a3437ae7]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x117b5bb)[0x7f28a34255bb]
/app/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1192d21)[0x7f28a343cd21]
Segmentation fault

Docker image is built FROM node:18-bullseye.

Amazon RDS reports that the database in question is an Aurora PostgreSQL version 14.3.

Prisma is version 4.3.0

And my schema.prisma

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("PRISMA__CLI__DATABASE_URL") // this is defined based on our database config when using package.json
}

model Article {
  id        Int         @id @default(autoincrement())
  title     String
}

I have tried setting engineType = "binary", but that makes my CI pipelines stall forever. My next step is to try to downgrade node and if that does not work, downgrade the DB.

Edit: for those interested I “generated” the segfault trace using segfault-handler, which will output the trace to both a file and stdout.

@aqrln

Environment variables loaded from .env
prisma                  : 4.12.0-integration-rtld-deepbind.3
@prisma/client          : 4.12.0-integration-rtld-deepbind.3
Current platform        : debian-openssl-3.0.x
Query Engine (Node-API) : libquery-engine 3b9f029aeb9a91829e6648c61146b02f3646d1e7 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
Migration Engine        : migration-engine-cli 3b9f029aeb9a91829e6648c61146b02f3646d1e7 (at node_modules/@prisma/engines/migration-engine-debian-openssl-3.0.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.12.0-22.3b9f029aeb9a91829e6648c61146b02f3646d1e7
Default Engines Hash    : 3b9f029aeb9a91829e6648c61146b02f3646d1e7
Studio                  : 0.483.0

About the other things, see #47416

Same for me: Running npm i prisma@4.12.0-integration-rtld-deepbind.3 did the trick!

Hey guys, also faced this Segmentation Fault when trying to connect to a Neon db inside a Github action. Using 4.12.0-integration-rtld-deepbind.3 version fixed it ✅ .

Also had this issue on prisma 4.12.0. Switching over to binary engine in the client fixed it for now. Would love to use the default library, but not super important as of now 😃

Thanks for looking into this, I saw that a change was potentially in flight already.

Node version: v18.15.0 Prisma version: v4.12.0

@aqrln I create a new issue #18510

@onepunchcat looking at your prisma -v output, you’re on 4.12.0-integration-views-fs.1 and not 4.12.0-integration-rtld-deepbind.3, could you please try again with 4.12.0-integration-rtld-deepbind.3?

Make sure to use an exact version in package.json without a ^ in the beginning so that the package manager won’t grab something unrelated that was published under the integration tag later.

For me the error changed when I change the engineType to binary.

PrismaClientKnownRequestError: 
realty-internal-api | Invalid `prisma.propertyClassification.findMany()` invocation

This only occurred on side by side query is runing like:

Promise.all([
  prisma.query1.findMany(),
  prisma.query2.findMany()
]);

// SIGSEGV when engineType is `library` and `PrismaClientKnownRequestError` when is `binary`.

// No problem when:
await  prisma.query1.findMany();
await  prisma.query2.findMany();

But during multiples request, even without Promise.all still happens. Maybe it is a concurrently problem. Just in alpine, in a full image (FROM node:18) of node it is ok.

@ferdiamg

Local: M1 MacBook (had to adapt Dockerfile and prisma.schema’s binaryTargets to make it work on M1, doesn’t affect prod)

could you please share your prisma.schema's binaryTargets config?

Sure thing binaryTargets = ["native", "linux-musl"] and adding OpenSSL to your Dockerfile RUN apt-get update && apt-get install -y openssl

Issue mentioned here: https://github.com/prisma/prisma/issues/8478#issuecomment-1095544159

FYI: If your distribution provides a build of Node.js 18 with OpenSSL 1.1.x, you can use that instead of the upstream Node.js build that vendors OpenSSL 3. This is the case on Alpine, where you can install nodejs-current from repository community: it provides (at the moment of writing) Node.js 18.6.0 linked with OpenSSL 1.1.1q, and the issue is not reproducible when using it.

(added this to the post above as well)

Like @zanzlender, I found that it when using node v17.9 and trying to connect to supabase, I was getting the segmentation fault. However, since I have switched to the LTS (at the time of this writing, it is v16.15.x) it works.

I have the issue in nodes v18.1 after switching from AWS Aurora compatible Postgres to standard PostgreSQL on AWS. It worked for a few hours today on node v16.15; then, it started throwing this error every time I ran a query.

Windows 11 & WLS2 Ubuntu

Edit: Node v16.15.0 works - I ran nvm set v16, and it only sets the version for the current terminal session. I set node to use v16 by default via nvm alias default 16.

Note here that Node.js v17 is not recommended because not LTS yet. https://nodejs.org/en/about/releases/

I would be curious to know if you can reproduce with Node.js v16, current LTS

If this is failing on older Node versions, we can hopefully reproduce with that and then figure out what is going on.

So far the messages on WSL2 have been Segmentation fault, and the messages on a Ubuntu VM have been Segmentation fault (core dumped)

Let’s close this then 👍

@sveisvei If Prisma not working on Pop!_OS is a general thing, could you maybe create an issue with reproduction steps so we can confirm this is the case and then potentially fix this? Thanks.

Tested with a fresh install of prisma-client @ 3.7.0, and the error did not occur anymore.