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

Prisma Connect Causes NodeJS to Close With Exit Code 0 #18336

Closed
lexi-the-cute opened this issue Mar 15, 2023 · 11 comments · Fixed by #18426
Closed

Prisma Connect Causes NodeJS to Close With Exit Code 0 #18336

lexi-the-cute opened this issue Mar 15, 2023 · 11 comments · Fixed by #18426
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: Next.js topic: segmentation fault
Milestone

Comments

@lexi-the-cute
Copy link

Bug description

Prisma causes nextjs dev environment to exit with code 0 after connection

How to reproduce

# Commands
npx prisma generate
npm run dev  # Crashes when loading http://127.0.0.1:3000/database
# When running production, the build process gets stuck
npx prisma generate
npm run build  # Never gets past this
npm run start

I don't have a pages directory, I only have an app directory. The client exits no matter if using route.ts(x) or page.ts(x)

Expected behavior

Prisma to retrieve all rows and not exit the nextjs app instead

Prisma information

// {root}/prisma/schema.prisma
generator client {
  provider = "prisma-client-js"
}

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

model test {
  id    BigInt  @id(map: "test_pk") @default(sequence())
  hello String?
}

model posts {
  id   BigInt  @id(map: "posts_pk") @default(sequence())
  slug String?
}
// {root}/app/database/page.tsx
// TODO: Find Out If Prisma Can Even Work In The App Directory
import prisma from '../../lib/prisma';

export default async function Page({params}) {
	const posts = await prisma.posts.findMany()  // This line is what causes the app to exit
	
// 	return (
// 		<div>
// 			<h1>Hello</h1>
// 			{posts.map((post) => (
// 				<div key={String(post.id)}>{post.slug}</div>
// 			))}
// 		</div>
// 	)
}
// {root}/lib/prisma.ts
// https://vercel.com/guides/nextjs-prisma-postgres#step-4.-install-and-generate-prisma-client
import { PrismaClient } from '@prisma/client';

let prisma: PrismaClient;

if (process.env.NODE_ENV === 'production') {
	prisma = new PrismaClient();
} else {
	if (!global.prisma) {
		global.prisma = new PrismaClient();
	}
	prisma = global.prisma;
}

export default prisma;

Environment & setup

  • OS: Debian
  • Database: CockroachDB
  • Node.js version: v19.7.0

Prisma Version

npx prisma -v

Environment variables loaded from .env
prisma                  : 4.11.0
@prisma/client          : 4.11.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 8fde8fef4033376662cad983758335009d522acb (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 8fde8fef4033376662cad983758335009d522acb (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.11.0-57.8fde8fef4033376662cad983758335009d522acb
Default Engines Hash    : 8fde8fef4033376662cad983758335009d522acb
Studio                  : 0.483.0
@lexi-the-cute lexi-the-cute added the kind/bug A reported bug. label Mar 15, 2023
@lexi-the-cute
Copy link
Author

I'll be adding the results of DEBUG="*" npm run dev > ~/Desktop/prisma.log 2>&1 once I ensure no private information is stored in the log

@lexi-the-cute
Copy link
Author

# ~/Desktop/prisma.log
> site@0.0.1 dev
> next dev

 ready  - started server on 0.0.0.0:3000, url: http://localhost:3000
 info   - Loaded env from /home/alexis/Desktop/site/.env
 warn   -  You have enabled experimental feature (appDir) in next.config.mjs. 
 warn   - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

 info   - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
2023-03-15T18:31:17.738Z next:jsconfig-paths-plugin tsconfig.json or jsconfig.json paths: {}
2023-03-15T18:31:17.739Z next:jsconfig-paths-plugin resolved baseUrl: /home/alexis/Desktop/site
 info   - automatically enabled Fast Refresh for 1 custom loader
2023-03-15T18:31:17.840Z next:jsconfig-paths-plugin tsconfig.json or jsconfig.json paths: {}
2023-03-15T18:31:17.840Z next:jsconfig-paths-plugin resolved baseUrl: /home/alexis/Desktop/site
2023-03-15T18:31:17.844Z next:jsconfig-paths-plugin tsconfig.json or jsconfig.json paths: {}
2023-03-15T18:31:17.844Z next:jsconfig-paths-plugin resolved baseUrl: /home/alexis/Desktop/site
 event  - compiled client and server successfully in 1042 ms (263 modules)
 wait   - compiling...
 wait   - compiling /database/page (client and server)...

2023-03-15T18:31:25.127Z next:jsconfig-paths-plugin paths are empty, bailing out
... (Redacted Because Same Message 1,000+ times)
2023-03-15T18:31:25.127Z next:jsconfig-paths-plugin paths are empty, bailing out

 event  - compiled client and server successfully in 6s (452 modules)
2023-03-15T18:31:25.589Z prisma:tryLoadEnv  Environment variables loaded from /home/alexis/Desktop/site/.env
2023-03-15T18:31:25.592Z prisma:tryLoadEnv  Environment variables loaded from /home/alexis/Desktop/site/.env
2023-03-15T18:31:25.593Z prisma:client  dirname /home/alexis/Desktop/site/node_modules/.prisma/client
2023-03-15T18:31:25.593Z prisma:client  relativePath ../../../prisma
2023-03-15T18:31:25.593Z prisma:client  cwd /home/alexis/Desktop/site/prisma
2023-03-15T18:31:25.593Z prisma:client  protocol graphql
2023-03-15T18:31:25.594Z prisma:client  clientVersion 4.11.0
2023-03-15T18:31:25.594Z prisma:client  clientEngineType library
2023-03-15T18:31:25.594Z prisma:client:libraryEngine  internalSetup
2023-03-15T18:31:25.668Z prisma:tryLoadEnv  Environment variables loaded from /home/alexis/Desktop/site/.env
2023-03-15T18:31:25.671Z prisma:tryLoadEnv  Environment variables loaded from /home/alexis/Desktop/site/.env
2023-03-15T18:31:25.671Z prisma:client  dirname /home/alexis/Desktop/site/node_modules/.prisma/client
2023-03-15T18:31:25.671Z prisma:client  relativePath ../../../prisma
2023-03-15T18:31:25.671Z prisma:client  cwd /home/alexis/Desktop/site/prisma
2023-03-15T18:31:25.672Z prisma:client  protocol graphql
2023-03-15T18:31:25.672Z prisma:client  clientVersion 4.11.0
2023-03-15T18:31:25.672Z prisma:client  clientEngineType library
2023-03-15T18:31:25.673Z prisma:client:libraryEngine  internalSetup
2023-03-15T18:31:25.600Z prisma:get-platform  Found distro info:
{
  "targetDistro": "debian",
  "familyDistro": "debian",
  "originalDistro": "debian"
}
2023-03-15T18:31:25.611Z prisma:get-platform  Command "uname -m" successfully returned "x86_64
"
2023-03-15T18:31:25.611Z prisma:get-platform  Trying platform-specific paths for "debian" (and "ubuntu")
2023-03-15T18:31:25.636Z prisma:get-platform  Command "ls -v "libssl.so.0*" /usr/lib/x86_64-linux-gnu | grep libssl.so | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
"
2023-03-15T18:31:25.636Z prisma:get-platform  Found libssl.so file using platform-specific paths: libssl.so.1.1

2023-03-15T18:31:25.636Z prisma:get-platform  The parsed libssl version is: 1.1.x
2023-03-15T18:31:25.637Z prisma:get-platform  Found distro info:
{
  "targetDistro": "debian",
  "familyDistro": "debian",
  "originalDistro": "debian"
}
2023-03-15T18:31:25.642Z prisma:get-platform  Command "uname -m" successfully returned "x86_64
"
2023-03-15T18:31:25.642Z prisma:get-platform  Trying platform-specific paths for "debian" (and "ubuntu")
2023-03-15T18:31:25.666Z prisma:get-platform  Command "ls -v "libssl.so.0*" /usr/lib/x86_64-linux-gnu | grep libssl.so | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
"
2023-03-15T18:31:25.666Z prisma:get-platform  Found libssl.so file using platform-specific paths: libssl.so.1.1

2023-03-15T18:31:25.667Z prisma:get-platform  The parsed libssl version is: 1.1.x
2023-03-15T18:31:25.668Z prisma:client:libraryEngine:loader  Searching for Query Engine Library in /home/alexis/Desktop/site/node_modules/.prisma/client
2023-03-15T18:31:25.668Z prisma:client:libraryEngine:loader  loadEngine using /home/alexis/Desktop/site/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
2023-03-15T18:31:25.760Z prisma:get-platform  Found distro info:
{
  "targetDistro": "debian",
  "familyDistro": "debian",
  "originalDistro": "debian"
}
2023-03-15T18:31:25.777Z prisma:get-platform  Command "uname -m" successfully returned "x86_64
"
2023-03-15T18:31:25.778Z prisma:get-platform  Trying platform-specific paths for "debian" (and "ubuntu")
2023-03-15T18:31:25.819Z prisma:get-platform  Command "ls -v "libssl.so.0*" /usr/lib/x86_64-linux-gnu | grep libssl.so | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
"
2023-03-15T18:31:25.819Z prisma:get-platform  Found libssl.so file using platform-specific paths: libssl.so.1.1

2023-03-15T18:31:25.819Z prisma:get-platform  The parsed libssl version is: 1.1.x
2023-03-15T18:31:25.821Z prisma:get-platform  Found distro info:
{
  "targetDistro": "debian",
  "familyDistro": "debian",
  "originalDistro": "debian"
}
2023-03-15T18:31:25.836Z prisma:get-platform  Command "uname -m" successfully returned "x86_64
"
2023-03-15T18:31:25.836Z prisma:get-platform  Trying platform-specific paths for "debian" (and "ubuntu")
2023-03-15T18:31:25.876Z prisma:get-platform  Command "ls -v "libssl.so.0*" /usr/lib/x86_64-linux-gnu | grep libssl.so | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
"
2023-03-15T18:31:25.876Z prisma:get-platform  Found libssl.so file using platform-specific paths: libssl.so.1.1

2023-03-15T18:31:25.877Z prisma:get-platform  The parsed libssl version is: 1.1.x
2023-03-15T18:31:25.878Z prisma:client:libraryEngine:loader  Searching for Query Engine Library in /home/alexis/Desktop/site/node_modules/.prisma/client
2023-03-15T18:31:25.878Z prisma:client:libraryEngine:loader  loadEngine using /home/alexis/Desktop/site/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node
2023-03-15T18:31:25.882Z prisma:client:libraryEngine  library starting

@lexi-the-cute
Copy link
Author

This is the log from when I commented out the code that causes the crash. Nothing else was changed in the code

# ~/Desktop/prisma-no-crash.log
> site@0.0.1 dev
> next dev

 ready  - started server on 0.0.0.0:3000, url: http://localhost:3000
 info   - Loaded env from /home/alexis/Desktop/site/.env
 warn   -  You have enabled experimental feature (appDir) in next.config.mjs. 
 warn   - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

 info   - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
2023-03-15T18:32:47.651Z next:jsconfig-paths-plugin tsconfig.json or jsconfig.json paths: {}
2023-03-15T18:32:47.652Z next:jsconfig-paths-plugin resolved baseUrl: /home/alexis/Desktop/site
2023-03-15T18:32:47.668Z next:jsconfig-paths-plugin tsconfig.json or jsconfig.json paths: {}
2023-03-15T18:32:47.668Z next:jsconfig-paths-plugin resolved baseUrl: /home/alexis/Desktop/site
2023-03-15T18:32:47.679Z next:jsconfig-paths-plugin tsconfig.json or jsconfig.json paths: {}
2023-03-15T18:32:47.680Z next:jsconfig-paths-plugin resolved baseUrl: /home/alexis/Desktop/site
 info   - automatically enabled Fast Refresh for 1 custom loader
 event  - compiled client and server successfully in 1497 ms (263 modules)
 wait   - compiling...
 wait   - compiling /database/page (client and server)...

2023-03-15T18:32:56.104Z next:jsconfig-paths-plugin paths are empty, bailing out
... (Redacted Because Same Message 1,000+ times)
2023-03-15T18:32:56.105Z next:jsconfig-paths-plugin paths are empty, bailing out

 event  - compiled client and server successfully in 6.6s (450 modules)
2023-03-15T18:32:56.565Z compression gzip compression
 error  - SyntaxError: "undefined" is not valid JSON
    at JSON.parse (<anonymous>)
2023-03-15T18:32:56.653Z send allow dotfile "/home/alexis/Desktop/site/.next/static/chunks/polyfills.js"
2023-03-15T18:32:56.654Z send stat "/home/alexis/Desktop/site/.next/static/chunks/polyfills.js"
2023-03-15T18:32:56.656Z send pipe "/home/alexis/Desktop/site/.next/static/chunks/polyfills.js"
2023-03-15T18:32:56.657Z send accept ranges
2023-03-15T18:32:56.657Z send modified Wed, 15 Mar 2023 18:32:48 GMT
2023-03-15T18:32:56.657Z send etag W/"16544-186e68bd39c"
2023-03-15T18:32:56.657Z send content-type application/javascript
2023-03-15T18:32:56.662Z send allow dotfile "/home/alexis/Desktop/site/.next/static/chunks/webpack.js"
2023-03-15T18:32:56.663Z send stat "/home/alexis/Desktop/site/.next/static/chunks/webpack.js"
2023-03-15T18:32:56.664Z send allow dotfile "/home/alexis/Desktop/site/.next/static/chunks/main-app.js"
2023-03-15T18:32:56.665Z send stat "/home/alexis/Desktop/site/.next/static/chunks/main-app.js"
2023-03-15T18:32:56.667Z send pipe "/home/alexis/Desktop/site/.next/static/chunks/webpack.js"
2023-03-15T18:32:56.667Z send accept ranges
2023-03-15T18:32:56.667Z send modified Wed, 15 Mar 2023 18:32:56 GMT
2023-03-15T18:32:56.668Z send etag W/"dac4-186e68beffc"
2023-03-15T18:32:56.668Z send content-type application/javascript
2023-03-15T18:32:56.668Z send pipe "/home/alexis/Desktop/site/.next/static/chunks/main-app.js"
2023-03-15T18:32:56.668Z send accept ranges
2023-03-15T18:32:56.669Z send modified Wed, 15 Mar 2023 18:32:48 GMT
2023-03-15T18:32:56.669Z send etag W/"4bc31a-186e68bd39c"
2023-03-15T18:32:56.669Z send content-type application/javascript
2023-03-15T18:32:56.670Z compression gzip compression
2023-03-15T18:32:56.671Z compression gzip compression
2023-03-15T18:32:56.672Z compression gzip compression
2023-03-15T18:32:57.125Z send allow dotfile "/home/alexis/Desktop/site/.next/static/chunks/app-client-internals.js"
2023-03-15T18:32:57.126Z send stat "/home/alexis/Desktop/site/.next/static/chunks/app-client-internals.js"
2023-03-15T18:32:57.126Z send pipe "/home/alexis/Desktop/site/.next/static/chunks/app-client-internals.js"
2023-03-15T18:32:57.126Z send accept ranges
2023-03-15T18:32:57.126Z send modified Wed, 15 Mar 2023 18:32:56 GMT
2023-03-15T18:32:57.126Z send etag W/"82e07-186e68bf000"
2023-03-15T18:32:57.126Z send content-type application/javascript
2023-03-15T18:32:57.127Z compression gzip compression

@lexi-the-cute
Copy link
Author

I just found out my copy of prisma studio segfaults too, so it may not be nextjs that's the issue

@lexi-the-cute
Copy link
Author

lexi-the-cute commented Mar 15, 2023

For some reason, Netlify was about to actually finish the build process this time, so I was able to verify that Prisma works in the Next.js app directory when it's not segfaulting. https://netlify.alexisart.me/database

On my Debian laptop, it still segfaults.

It's the phrase Hello world on two separate lines. Hello is built into the JSX response. world is pulled from a CockroachDB database via Prisma.

@janpio janpio added topic: Next.js bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. labels Mar 15, 2023
@janpio
Copy link
Member

janpio commented Mar 15, 2023

Maybe read through these and see if there is a workaround that might work for you: https://github.com/prisma/prisma/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22topic%3A+segmentation+fault%22

@lexi-the-cute
Copy link
Author

I had tested #10649 (comment) and setting engineType = "binary" does provide a workaround which allows me to use Prisma in my dev environment. Prisma Studio still segfaults though

@aqrln
Copy link
Member

aqrln commented Mar 22, 2023

Hi @alexisart and thank you for the report! 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. Since your bug report is a bit different than other similar ones and you're using CockroachDB and not Postgres, it would be especially valuable to know if it works in your case.

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!

@lexi-the-cute
Copy link
Author

4.12.0-integration-rtld-deepbind.3

Yes, this fixes the issue both for Prisma studio and for not using engineType = "binary"

@aqrln aqrln reopened this Mar 31, 2023
@aqrln
Copy link
Member

aqrln commented Mar 31, 2023

Thank you for checking and for confirming! I'm going to leave this issue open for now since #18426 is not merged yet, we are now confident that it works and doesn't introduce any unwanted side effects, and will work on finalizing and releasing it ASAP.

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.


For future readers:

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/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: Next.js topic: segmentation fault
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants