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

Segmentation Fault in Postgres #17946

Closed
josejaviersanahuja opened this issue Feb 14, 2023 · 16 comments · Fixed by #18426
Closed

Segmentation Fault in Postgres #17946

josejaviersanahuja opened this issue Feb 14, 2023 · 16 comments · Fixed by #18426
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: postgresql topic: segmentation fault
Milestone

Comments

@josejaviersanahuja
Copy link

josejaviersanahuja commented Feb 14, 2023

I am studying prisma to use it. But I haven't been able to use it since my first attemp is showing me this error.

[1] 6655 segmentation fault node src/seed.js

[1] 5817 segmentation fault ts-node src/seed.ts

I made the models, I run the migration but I can't use prismaClient.

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function seed () {
  await prisma.$connect()
  console.log('Seeding database...', prisma.$connect)
}

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

Adding package.json and tsconfig

{ ...
"prisma": {
    "seed": "ts-node prisma/seed.ts"
  },
  "dependencies": {
    "@prisma/client": "^4.10.1",
    "@trpc/server": "^10.9.1",
    "cors": "^2.8.5",
    "debug": "^4.3.4",
    "express": "^4.18.2",
    "http-errors": "^2.0.0",
    "morgan": "^1.10.0",
    "zod": "^3.20.2"
  },
  "devDependencies": {
    "@types/cors": "^2.8.13",
    "@types/debug": "^4.1.7",
    "@types/express": "^4.17.16",
    "@types/http-errors": "^2.0.1",
    "@types/morgan": "^1.9.4",
    "@types/node": "^18.11.18",
    "@typescript-eslint/eslint-plugin": "^5.50.0",
    "@typescript-eslint/parser": "^5.50.0",
    "eslint": "^8.33.0",
    "eslint-config-standard": "^17.0.0",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-n": "^15.6.1",
    "eslint-plugin-promise": "^6.1.1",
    "prisma": "^4.10.1",
    "ts-node": "^10.9.1",
    "ts-node-dev": "^2.0.0",
    "typescript": "^4.9.5"
  }
}

{
  "compilerOptions": {
    "target": "es2016",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "lib": ["es2016", "esnext.asynciterable"],           /* Specify a set of bundled library declaration files that describe the target runtime environment. */
    "module": "commonjs",                                /* Specify what module code is generated. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
    "strict": true,                                      /* Enable all strict type-checking options. */
    "skipLibCheck": true,   
}

POSTGRES VERSION

psql (15.1 (Debian 15.1-1.pgdg110+1), servidor 14.6 (Debian 14.6-1.pgdg110+1))
Conexión SSL (protocolo: TLSv1.3, cifrado: TLS_AES_256_GCM_SHA384, compresión: desactivado)
@janpio janpio transferred this issue from prisma/docs Feb 15, 2023
@janpio janpio added team/client Issue for team Client. topic: segmentation fault bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. labels Feb 16, 2023
@aqrln aqrln added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Feb 17, 2023
@aqrln
Copy link
Member

aqrln commented Feb 17, 2023

Hi @josejaviersanahuja! Could you please provide more information so we could try to reproduce it? What is your Prisma version, Node.js version, your operating system and the database you are using?

@josejaviersanahuja josejaviersanahuja changed the title Segmentation Fault Segmentation Fault in Postgres Feb 17, 2023
@josejaviersanahuja
Copy link
Author

Dear @aqrln I have tried to run again everything with less packages and with a different database. In Mysql the problem doesn't happen, only with postgres.

I use Postgres 15.1 and Debian 11. Node 18.1.

psql (15.1 (Debian 15.1-1.pgdg110+1), servidor 14.6 (Debian 14.6-1.pgdg110+1))
Conexión SSL (protocolo: TLSv1.3, cifrado: TLS_AES_256_GCM_SHA384, compresión: desactivado)

New test with less packages

"prisma": {
    "seed": "ts-node prisma/seed.ts"
  },
  "devDependencies": {
    "@types/node": "^18.13.0",
    "prisma": "^4.10.1",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.5"
  },
  "dependencies": {
    "@prisma/client": "^4.10.1"
  }

@josejaviersanahuja
Copy link
Author

Dear all.

I had to delete my postgres installation. I started using postgres in docker and is working fine.

It could have been a custom config that blew everything on my end. Sorry I couldn't help with this

Thanks in advance

@LunarMelody
Copy link

I have the same issue on Debian 11 with PostgreSQL 15.1 and Node 18.14.2, couldn't find any way to fix it tho. Tried installing Postgres 14 and still getting the error.

@aqrln
Copy link
Member

aqrln commented Mar 22, 2023

@josejaviersanahuja no worries, given the information in your previous message I'm pretty sure it was the same problem as #10649.


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

@zruq
Copy link

zruq commented Apr 1, 2023

@aqrln Hello I had the same segmentation fault problem (node v18.15.0, Ubuntu WSL) and updating prisma, @prisma/client to 4.12.0-integration-rtld-deepbind.3 fixed it. Thanks!

@LunarMelody
Copy link

@josejaviersanahuja no worries, given the information in your previous message I'm pretty sure it was the same problem as #10649.

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

Ah, sorry for the late reply. I had to switch from Debian to Ubuntu, since it was basically production deployment of some project, so yeah, can't really do that now. I'll try tomorrow on my own VPS tho 👍

@andreasciamanna
Copy link

After reading this, I looked forward to seeing my SEGFAULT errors disappear.

Unfortunately, this is not the case for me.

$ prisma -v
Environment variables loaded from .env
prisma                  : 4.12.0-integration-rtld-deepbind.3
@prisma/client          : 4.12.0
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
$ find node_modules -name \*.node
node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node
node_modules/prisma/libquery_engine-debian-openssl-3.0.x.so.node
node_modules/prisma/engines/659ef412370fa3b41cd7bf6e94587c1dfb7f67e7/libquery_engine-debian-openssl-3.0.x.so.node
node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node
$ node -v
v18.15.0
$  uname -a
Linux {...} 5.19.0-38-generic #39-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 17:33:16 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

After trying npm rebuild as well (not sure if that was meant to be done).

@aqrln
Copy link
Member

aqrln commented Apr 6, 2023

@andreasciamanna two things here:

  1. Your @prisma/client is 4.12.0 which doesn't contain the fix yet. You need to pin @prisma/client to 4.12.0-integration-rtld-deepbind.3 too and not just the prisma CLI to test that patch.
  2. That said, it indeed might not fix the issue for you given debian-openssl-3.0.x and Node.js 18: it looks like you might actually be facing a different problem than most people who reported the issue.

Could you please try that just in case anyway, and then open a new issue describing your setup and any info you could provide for reproduction? Thank you!

@andreasciamanna
Copy link

andreasciamanna commented Apr 6, 2023

@aqrln I think I already had done this when I wrote my previous message: prisma: 4.12.0-integration-rtld-deepbind.3.

What am I missing?

@aqrln
Copy link
Member

aqrln commented Apr 6, 2023

@andreasciamanna no, you didn’t:

prisma                  : 4.12.0-integration-rtld-deepbind.3
@prisma/client          : 4.12.0

You're missing the other package, @prisma/client. The one you pinned to the dev version is just the CLI, not the client, it doesn’t use the Query Engine.

@LunarMelody
Copy link

Hey! Sorry for being so late once again, just got a chance to test this. The issue seems to be present.

$ prisma db seed
Environment variables loaded from .env
Running seed command `ts-node --require tsconfig-paths/register prisma/seed.ts` ...

An error occurred while running the seed command:
Error: Command was killed with SIGSEGV (Segmentation fault): ts-node --require tsconfig-paths/register prisma/seed.ts
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

And some versions here

prisma --version
Environment variables loaded from .env
prisma                  : 4.12.0
@prisma/client          : 4.12.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 659ef412370fa3b41cd7bf6e94587c1dfb7f67e7 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 659ef412370fa3b41cd7bf6e94587c1dfb7f67e7 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7
Default Engines Hash    : 659ef412370fa3b41cd7bf6e94587c1dfb7f67e7
Studio                  : 0.483.0
Preview Features        : fullTextSearch, postgresqlExtensions
$ node -v
v18.15.0

@aqrln
Copy link
Member

aqrln commented Apr 6, 2023

@TenkoSpirit hi, no worries. Regarding the versions, looks like you're using the stable 4.12.0 here too:

prisma                  : 4.12.0
@prisma/client          : 4.12.0

I think this might have happened if you used a non-exact version (^4.12.0-integration-rtld-deepbind.3) and the package manager (in this case incorrectly, though reasonably from the point of view of semver) updated it to 4.12.0.

Here's a newer integration version as a pre-release of 4.13: 4.13.0-integration-rtld-deepbind.6. I'd still recommend to specify it as exact version as using ^ with dev versions may lead to unexpected results sometimes.

@andreasciamanna
Copy link

You're missing the other package, @prisma/client. The one you pinned to the dev version is just the CLI, not the client, it doesn’t use the Query Engine.

Oops... Thanks.

I confirm it works now. Or at least, I didn't get the segfault since I've upgraded.

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.

@iMerica
Copy link

iMerica commented Feb 3, 2024

There seems to be wide confusion on the big picture here. The segmentation fault is happening on the database server. It has nothing to do with Prisma (the database client). If you're seeing this in your local environment, it probably has to do with running the docker image postgres:latest on Apple Silicon (e.g M3 Macbook Pro)

$ docker-compose logs -f postgres
postgres  | 2024-02-03 21:25:10.678 UTC [1] LOG:  database system is ready to accept connections
postgres  | qemu: uncaught target signal 11 (Segmentation fault) - core dumped
postgres  | 2024-02-03 21:28:20.626 UTC [1] LOG:  server process (PID 5518) was terminated by signal 11: Segmentation fault

So the appropriate action item for the Prisma core team is to improve the try/retry logic when encountering any db server side errors related to connections dropping, irrespective of the root cause (e.g seg fault).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: postgresql topic: segmentation fault
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants