Skip to content
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

Debian 11 Node 19.3.0 segmentation fault #16897

Closed
wvhulle opened this issue Dec 19, 2022 · 11 comments · Fixed by #18426
Closed

Debian 11 Node 19.3.0 segmentation fault #16897

wvhulle opened this issue Dec 19, 2022 · 11 comments · Fixed by #18426
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: node version topic: openssl topic: segmentation fault
Milestone

Comments

@wvhulle
Copy link

wvhulle commented Dec 19, 2022

Bug description

Some code based on the official Prisma getting started fails with a segmentation fault.

dsp@dsp2 ~/hello-prisma> npx ts-node script.ts
PID 1132357 received SIGSEGV for address: 0x1000001b7
/home/dsp/hello-prisma/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x2e65)[0x7f0bda818e65]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13140)[0x7f0bda4d4140]
/lib/x86_64-linux-gnu/libssl.so.1.1(SSL_get_peer_certificate+0x13)[0x7f0bd805b143]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1187917)[0x7f0bc346d917]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xd40070)[0x7f0bc3026070]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xd6c59c)[0x7f0bc305259c]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xe26140)[0x7f0bc310c140]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xeaa1d9)[0x7f0bc31901d9]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xdd83dc)[0x7f0bc30be3dc]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xeaeda6)[0x7f0bc3194da6]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xe699e0)[0x7f0bc314f9e0]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x7fad58)[0x7f0bc2ae0d58]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x801609)[0x7f0bc2ae7609]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x78bc85)[0x7f0bc2a71c85]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x793f63)[0x7f0bc2a79f63]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x81a69f)[0x7f0bc2b0069f]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x7eb08b)[0x7f0bc2ad108b]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x7fe240)[0x7f0bc2ae4240]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1beb48)[0x7f0bc24a4b48]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x24b079)[0x7f0bc2531079]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1d8c35)[0x7f0bc24bec35]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1a370d)[0x7f0bc248970d]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1b7ee6)[0x7f0bc249dee6]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1979e7)[0x7f0bc247d9e7]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1656ba)[0x7f0bc244b6ba]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x116ab65)[0x7f0bc3450b65]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1165abd)[0x7f0bc344babd]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1164d70)[0x7f0bc344ad70]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1168e57)[0x7f0bc344ee57]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1164849)[0x7f0bc344a849]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x115b981)[0x7f0bc3441981]
/home/dsp/hello-prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x1155869)[0x7f0bc343b869]
Segmentation fault

It is fine with node 16.16.0 but not node 19.3.0. I have tested also older versions of prisma but those don't work neither.

How to reproduce

  1. clone https://github.com/wvhulle/node-v19.3.0-prisma-4.7.1-bug
  2. npm install
  3. npx generate
  4. npx ts-node script.ts

Expected behavior

Run without error and output

Prisma information

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

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

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}
import { PrismaClient } from '@prisma/client'
import SegfaultHandler from "segfault-handler"

const prisma = new PrismaClient()

async function main() {

  SegfaultHandler.registerHandler("crash.log")
  const user = await prisma.user.findMany({

    where: {
      name: 'Alice',
      email: 'alice@prisma.io',
    },
  })
  console.log(user)
}

main()
  .then(async () => {
    await prisma.$disconnect()
  })

  .catch(async (e) => {
    console.error(e)
    await prisma.$disconnect()
    process.exit(1)
  })

Environment & setup

  • OS: Debian GNU/Linux 11 (bullseye)
  • Database: PostgreSQL
  • Node.js version: 19.3.0

Prisma Version

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

@wvhulle wvhulle added the kind/bug A reported bug. label Dec 19, 2022
@aqrln
Copy link
Member

aqrln commented Dec 20, 2022

Thank you for the report! This looks like a duplicate of #10649, please see #10649 (comment) for the list of workarounds. TLDR: ensure that the version of OpenSSL used by Node.js is compatible with your system OpenSSL. If that is not possible, as the last resort you can try switching to the binary engine, but it is not recommended and may have worse performance.

Could you provide some more details about your PostgreSQL deployment? Is it a local database or something like AWS RDS?

@aqrln aqrln added bug/2-confirmed Bug has been reproduced and confirmed. tech/engines Issue for tech Engines. team/client Issue for team Client. labels Dec 20, 2022
@20vitality12
Copy link

@wvhulle I had same with node 18.12.1 and prisma 4.7.1.
Update prisma to 4.8.1 and using FROM node:18.12.1-alpine3.16 fix this issue.

@dangdennis
Copy link

dangdennis commented Jan 20, 2023

I encountered this problem suddenly since a few days ago too. The strange part is we had no changes in docker image or node dependencies for nearly 2 weeks.

I am able to reproduce.

Environment

node:18.2-bullseye-slim image (debian)
prisma 4.8.0

Steps to reproduce

  1. Start from Fly's express example link
  2. Install prisma and @prisma/client 4.8.0
  3. Update dockerfile with contents below under ##Dockerfile
  4. Deploy to Fly via fly launch, connect to their test postgres container. I am slightly cheating here because I connect to a cockroachdb serverless cluster.
  5. Check out their logs to see something like
    • 2023-01-20T03:32:18Z   [info]Preparing to run: `npm run start` as root
      2023-01-20T03:32:18Z   [info]2023/01/20 03:32:18 listening on [fdaa:0:75bf:a7b:95:9f47:f343:2]:22 (DNS: [fdaa::3]:53)
      2023-01-20T03:32:19Z   [info]> hellonode@1.0.0 start
      2023-01-20T03:32:19Z   [info]> node server.js
      2023-01-20T03:32:21Z   [info]npmmentation fault
      2023-01-20T03:32:21Z   [info]npm notice
      2023-01-20T03:32:21Z   [info]npm notice New major version of npm available! 8.19.2 -> 9.3.1
      2023-01-20T03:32:21Z   [info]npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.3.1>
      2023-01-20T03:32:21Z   [info]npm notice Run `npm install -g npm@9.3.1` to update!
      2023-01-20T03:32:21Z   [info]npm notice
      2023-01-20T03:32:21Z   [info]Starting clean up.
      --> v2 failed - Failed due to unhealthy allocations - rolling back to job version 1 and deploying as v3 
      

Dockerfile

FROM debian:bullseye as builder

ARG NODE_VERSION=18.12.0

RUN apt-get update; apt install -y curl python-is-python3 pkg-config build-essential
RUN curl https://get.volta.sh | bash
ENV VOLTA_HOME /root/.volta
ENV PATH /root/.volta/bin:$PATH
RUN volta install node@${NODE_VERSION}

#######################################################################

RUN mkdir /app
WORKDIR /app

ENV NODE_ENV production

COPY . .

RUN npm install
RUN npx prisma generate

FROM debian:bullseye

LABEL fly_launch_runtime="nodejs"

COPY --from=builder /app/node_modules/.prisma /app/node_modules/.prisma
COPY --from=builder /root/.volta /root/.volta
COPY --from=builder /app /app

WORKDIR /app
ENV NODE_ENV production
ENV PATH /root/.volta/bin:$PATH


CMD [ "npm", "run", "start" ]

@wvhulle
Copy link
Author

wvhulle commented Jan 21, 2023

Still failing on latest Prisma upgrade. I don't understand how I can fix it. How do I use other openssl?

@wvhulle
Copy link
Author

wvhulle commented Jan 21, 2023

Thank you for the report! This looks like a duplicate of #10649, please see #10649 (comment) for the list of workarounds. TLDR: ensure that the version of OpenSSL used by Node.js is compatible with your system OpenSSL. If that is not possible, as the last resort you can try switching to the binary engine, but it is not recommended and may have worse performance.

Could you provide some more details about your PostgreSQL deployment? Is it a local database or something like AWS RDS?

It is a database running on a local debian 11 server. Postgres version 15.1. The segfault handler still gives

PID 1601637 received SIGSEGV for address: 0x1000001b7
/home/dsp/prisma/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x3236)[0x7f3187dbe236]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13140)[0x7f3187a79140]
/lib/x86_64-linux-gnu/libssl.so.1.1(SSL_get_peer_certificate+0x13)[0x7f318407c143]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x562648)[0x7f316dd04648]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x5a60dd)[0x7f316dd480dd]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x5a2b18)[0x7f316dd44b18]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x63f295)[0x7f316dde1295]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x842935)[0x7f316dfe4935]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x83e609)[0x7f316dfe0609]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x83e4cf)[0x7f316dfe04cf]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x875b84)[0x7f316e017b84]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x8b1f2c)[0x7f316e053f2c]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x875e60)[0x7f316e017e60]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x8b35e3)[0x7f316e0555e3]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x12ba40)[0x7f316d8cda40]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0xfa63c)[0x7f316d89c63c]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x90a413)[0x7f316e0ac413]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x914aaa)[0x7f316e0b6aaa]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x90945a)[0x7f316e0ab45a]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x908ddc)[0x7f316e0aaddc]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x90cf64)[0x7f316e0aef64]
/home/dsp/prisma/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node(+0x8f2af5)[0x7f316e094af5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x7ea7)[0x7f3187a6dea7]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7f318798da2f]
Segmentation fault

Using `binaryTargets = ["native"] does not change this.

@wvhulle
Copy link
Author

wvhulle commented Jan 21, 2023

It is solved by using engineType = "binary". Is it possible to use library? I have installed openssl 3 but i don't know how to point node and prisma to use it.

@dangdennis
Copy link

@wvhulle check out their prisma docs. In the prisma schema file, you’ll see how to set the native target.

@wvhulle
Copy link
Author

wvhulle commented Mar 6, 2023

Upgrading to debian unstable with openssl 3.0.7 fixed this temporarily but after reboot I get a segmentation fault again on prisma.$connect and prisma._engine.start(). Adding debian openssl 3 to binarytarget does not work, even though the versions are correct.

@aqrln
Copy link
Member

aqrln commented Mar 22, 2023

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 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!

@dvlkv
Copy link

dvlkv commented Apr 8, 2023

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 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!

This version solves problem for me. Thank you!
Node: 19.8.1
OS: Debian 11 (amd64)

aqrln added a commit that referenced this issue Apr 14, 2023
@janpio janpio added this to the 4.13.0 milestone Apr 15, 2023
@aqrln
Copy link
Member

aqrln commented Apr 17, 2023

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 #18510 or open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: node version topic: openssl topic: segmentation fault
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@janpio @Jolg42 @aqrln @wvhulle @dvlkv @dangdennis @20vitality12 and others