prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
Apache License 2.0
1.47k stars 67 forks source link

Operation not permitted (os error 1) #923

Closed typeofweb closed 4 years ago

typeofweb commented 4 years ago

Bug description

Trying to run even the simplest query results in an error: Operation not permitted (os error 1)

How to reproduce

My code:

import { PrismaClient } from '@prisma/client';

const client = new PrismaClient({ log: ['query', 'info', 'warn'] });

export const initDb = async () => {
  console.log(await client.$queryRaw`SELECT 1=1;`);
};

initDb();

Expected behavior

Prisma information

DEBUG="*" node app.js
  prisma-client {
  prisma-client   engineConfig: {
  prisma-client     cwd: '/usr/home/……/myproject/apps/api/prisma',
  prisma-client     enableDebugLogs: false,
  prisma-client     enableEngineDebugMode: undefined,
  prisma-client     datamodelPath: '/usr/home/……/myproject/node_modules/.prisma/client/schema.prisma',
  prisma-client     prismaPath: undefined,
  prisma-client     engineEndpoint: undefined,
  prisma-client     generator: {
  prisma-client       name: 'client',
  prisma-client       provider: 'prisma-client-js',
  prisma-client       output: '/usr/home/……/myproject/node_modules/@prisma/client',
  prisma-client       binaryTargets: [],
  prisma-client       previewFeatures: [],
  prisma-client       config: {}
  prisma-client     },
  prisma-client     showColors: false,
  prisma-client     logLevel: 'info',
  prisma-client     logQueries: true,
  prisma-client     flags: [],
  prisma-client     clientVersion: '2.10.0',
  prisma-client     enableExperimental: [],
  prisma-client     useUds: undefined
  prisma-client   }
  prisma-client } +0ms
  plusX Execution permissions of /home/……/prisma-engines/target/release/query-engine are fine +0ms
  engine port: undefined +0ms
  prisma-client prisma.queryRaw(SELECT 1=1;, []) +2s
  prisma-client Prisma Client call: +0ms
  prisma-client Prisma Client call: +20ms
  prisma-client prisma.queryRaw({
  prisma-client   query: 'SELECT 1=1;',
  prisma-client   parameters: {
  prisma-client     values: '[]',
  prisma-client     __prismaRawParamaters__: true
  prisma-client   }
  prisma-client }) +2ms
  prisma-client Generated request: +0ms
  prisma-client mutation {
  prisma-client   queryRaw(
  prisma-client     query: "SELECT 1=1;"
  prisma-client     parameters: "[]"
  prisma-client   )
  prisma-client }
  prisma-client  +0ms
  engine {
  engine   cwd: '/usr/home/……/myproject/apps/api/prisma'
  engine } +52ms
  plusX Execution permissions of /home/……/prisma-engines/target/release/query-engine are fine +53ms
  engine { flags: [ '--enable-raw-queries' ] } +0ms
  engine port: 16893 +3ms
  engine data Oct 29 18:37:48.965 TRACE query_engine::exec_loader: Loading Postgres connector... +22ms
  engine SyntaxError: Unexpected token  in JSON at position 0
  engine     at JSON.parse (<anonymous>)
  engine     at LineStream.<anonymous> (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:9439:33)
  engine     at LineStream.emit (events.js:311:20)
  engine     at addChunk (_stream_readable.js:294:12)
  engine     at readableAddChunk (_stream_readable.js:275:11)
  engine     at LineStream.Readable.push (_stream_readable.js:209:10)
  engine     at LineStream.Transform.push (_stream_transform.js:152:32)
  engine     at LineStream._pushBuffer (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4670:19)
  engine     at LineStream._transform (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4664:10)
  engine     at LineStream.Transform._read (_stream_transform.js:191:10) Oct 29 18:37:48.965 TRACE query_engine::exec_loader: Loading Postgres connector... +1ms
  engine data Oct 29 18:37:48.966  INFO quaint::pooled: Starting a postgresql pool with 25 connections. +1ms
  engine SyntaxError: Unexpected token  in JSON at position 0
  engine     at JSON.parse (<anonymous>)
  engine     at LineStream.<anonymous> (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:9439:33)
  engine     at LineStream.emit (events.js:311:20)
  engine     at addChunk (_stream_readable.js:294:12)
  engine     at readableAddChunk (_stream_readable.js:275:11)
  engine     at LineStream.Readable.push (_stream_readable.js:209:10)
  engine     at LineStream.Transform.push (_stream_transform.js:152:32)
  engine     at LineStream._pushBuffer (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4670:19)
  engine     at LineStream._transform (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4664:10)
  engine     at LineStream.Transform._read (_stream_transform.js:191:10) Oct 29 18:37:48.966  INFO quaint::pooled: Starting a postgresql pool with 25 connections. +0ms
  engine data Oct 29 18:37:48.966 TRACE query_engine::exec_loader: Loaded Postgres connector. +1ms
  engine SyntaxError: Unexpected token  in JSON at position 0
  engine     at JSON.parse (<anonymous>)
  engine     at LineStream.<anonymous> (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:9439:33)
  engine     at LineStream.emit (events.js:311:20)
  engine     at addChunk (_stream_readable.js:294:12)
  engine     at readableAddChunk (_stream_readable.js:275:11)
  engine     at LineStream.Readable.push (_stream_readable.js:209:10)
  engine     at LineStream.Transform.push (_stream_transform.js:152:32)
  engine     at LineStream._pushBuffer (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4670:19)
  engine     at LineStream._transform (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4664:10)
  engine     at LineStream.Transform._read (_stream_transform.js:191:10) Oct 29 18:37:48.966 TRACE query_engine::exec_loader: Loaded Postgres connector. +0ms
  engine data Oct 29 18:37:48.987 DEBUG quaint::pooled::manager: Acquired database connection. +18ms
  engine SyntaxError: Unexpected token  in JSON at position 0
  engine     at JSON.parse (<anonymous>)
  engine     at LineStream.<anonymous> (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:9439:33)
  engine     at LineStream.emit (events.js:311:20)
  engine     at addChunk (_stream_readable.js:294:12)
  engine     at readableAddChunk (_stream_readable.js:275:11)
  engine     at LineStream.Readable.push (_stream_readable.js:209:10)
  engine     at LineStream.Transform.push (_stream_transform.js:152:32)
  engine     at LineStream._pushBuffer (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4670:19)
  engine     at LineStream._transform (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4664:10)
  engine     at LineStream.Transform._read (_stream_transform.js:191:10) Oct 29 18:37:48.987 DEBUG quaint::pooled::manager: Acquired database connection. +0ms
  engine data Oct 29 18:37:48.987  INFO query_engine::server: Started http server +1ms
  engine SyntaxError: Unexpected token  in JSON at position 0
  engine     at JSON.parse (<anonymous>)
  engine     at LineStream.<anonymous> (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:9439:33)
  engine     at LineStream.emit (events.js:311:20)
  engine     at addChunk (_stream_readable.js:294:12)
  engine     at readableAddChunk (_stream_readable.js:275:11)
  engine     at LineStream.Readable.push (_stream_readable.js:209:10)
  engine     at LineStream.Transform.push (_stream_transform.js:152:32)
  engine     at LineStream._pushBuffer (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4670:19)
  engine     at LineStream._transform (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4664:10)
  engine     at LineStream.Transform._read (_stream_transform.js:191:10) Oct 29 18:37:48.987  INFO query_engine::server: Started http server +0ms
  engine data Oct 29 18:37:48.987  INFO query_engine: Encountered error during initialization: +0ms
  engine SyntaxError: Unexpected token  in JSON at position 0
  engine     at JSON.parse (<anonymous>)
  engine     at LineStream.<anonymous> (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:9439:33)
  engine     at LineStream.emit (events.js:311:20)
  engine     at addChunk (_stream_readable.js:294:12)
  engine     at readableAddChunk (_stream_readable.js:275:11)
  engine     at LineStream.Readable.push (_stream_readable.js:209:10)
  engine     at LineStream.Transform.push (_stream_transform.js:152:32)
  engine     at LineStream._pushBuffer (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4670:19)
  engine     at LineStream._transform (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4664:10)
  engine     at LineStream.Transform._read (_stream_transform.js:191:10) Oct 29 18:37:48.987  INFO query_engine: Encountered error during initialization: +0ms
  engine stderr {"is_panic":false,"message":"Operation not permitted (os error 1)","backtrace":"   0: <unknown>\n   1: <unknown>\n   2: <unknown>\n   3: <unknown>\n   4: <unknown>\n   5: <unknown>\n   6: <unknown>\n   7: <unknown>\n   8: <unknown>\n   9: <unknown>\n  10: <unknown>\n  11: <unknown>\n  12: <unknown>\n  13: <unknown>\n  14: <unknown>\n  15: <unknown>\n  16: <unknown>\n  17: <unknown>\n"} +1ms
  engine {
  engine   is_panic: false,
  engine   message: 'Operation not permitted (os error 1)',
  engine   backtrace: '   0: <unknown>\n' +
  engine     '   1: <unknown>\n' +
  engine     '   2: <unknown>\n' +
  engine     '   3: <unknown>\n' +
  engine     '   4: <unknown>\n' +
  engine     '   5: <unknown>\n' +
  engine     '   6: <unknown>\n' +
  engine     '   7: <unknown>\n' +
  engine     '   8: <unknown>\n' +
  engine     '   9: <unknown>\n' +
  engine     '  10: <unknown>\n' +
  engine     '  11: <unknown>\n' +
  engine     '  12: <unknown>\n' +
  engine     '  13: <unknown>\n' +
  engine     '  14: <unknown>\n' +
  engine     '  15: <unknown>\n' +
  engine     '  16: <unknown>\n' +
  engine     '  17: <unknown>\n'
  engine } +1ms
  prisma-client Error: Operation not permitted (os error 1)
  prisma-client     at LineStream.<anonymous> (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:9424:31)
  prisma-client     at LineStream.emit (events.js:311:20)
  prisma-client     at addChunk (_stream_readable.js:294:12)
  prisma-client     at readableAddChunk (_stream_readable.js:275:11)
  prisma-client     at LineStream.Readable.push (_stream_readable.js:209:10)
  prisma-client     at LineStream.Transform.push (_stream_transform.js:152:32)
  prisma-client     at LineStream._pushBuffer (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4670:19)
  prisma-client     at LineStream._transform (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:4664:10)
  prisma-client     at LineStream.Transform._read (_stream_transform.js:191:10)
  prisma-client     at LineStream.Transform._write (_stream_transform.js:179:12) +51ms
PrismaClientInitializationError2:
Invalid `prisma.queryRaw()` invocation:

  Operation not permitted (os error 1)
    at PrismaClientFetcher.request (/usr/home/……/myproject/node_modules/@prisma/client/runtime/index.js:15782:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  clientVersion: '2.10.0'
}

Environment & setup

typeofweb commented 4 years ago

I figured that if I hardcode getFreePort() to always return the same port which I manually opened, the Operation not permitted error is gone. Is there a way to override the port?

pantharshit00 commented 4 years ago

@mmiszy

Try using the UDS mode (Unix domain sockets). That won't open the port in the first place.

const client = new PrismaClient({ __internal: { useUds: true }} as any); // omit as any if you are not using typescript

We plan to make this the default in the near future.

typeofweb commented 4 years ago

Thank you, that solves it.

Sorry, I wasn't sure which repo is the right one to open issues.

pantharshit00 commented 4 years ago

It is alright, we usually transfer issues to appropriate place so no need to open things twice in the future :)