blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

Prisma error connection refused #174

Closed karimsx closed 3 years ago

karimsx commented 3 years ago

What is the problem?

prisma client can't connect to database

Paste all your error logs here:

~/etudesnet/mono >>> npm run start                                                                                                                                                                                                    ±[●●][master]

> mono@1.0.0 start /home/fragx1011/etudesnet/mono
> blitz start

You are using beta software - if you have any problems, please open an issue here:
      https://github.com/blitz-js/blitz/issues/new/choose

  detect-port detect free port between [3000, 3010) +0ms
  detect-port get free null:3000 +2ms
  detect-port get free 0.0.0.0:3000 +1ms
  detect-port get free localhost:3000 +2ms
  detect-port get free 10.118.144.7:3000 +1ms
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from /home/fragx1011/etudesnet/mono/.env
warn  - You have enabled experimental feature(s).
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use them at your own risk.

2021-03-26T13:17:25.754Z prisma:tryLoadEnv Environment variables loaded from /home/fragx1011/etudesnet/mono/.env
[dotenv][DEBUG] did not match key and value when parsing line 1: # This env file should be checked into source control
[dotenv][DEBUG] did not match key and value when parsing line 2: # This is the place for default values for all environments
[dotenv][DEBUG] did not match key and value when parsing line 3: # Values in `.env.local` and `.env.production` will override these values
[dotenv][DEBUG] "DATABASE_URL" is already defined in `process.env` and will not be overwritten
[dotenv][DEBUG] "SESSION_SECRET_KEY" is already defined in `process.env` and will not be overwritten
[dotenv][DEBUG] "DEBUG" is already defined in `process.env` and will not be overwritten
2021-03-26T13:17:25.756Z prisma:tryLoadEnv Environment variables loaded from /home/fragx1011/etudesnet/mono/.env
[dotenv][DEBUG] did not match key and value when parsing line 1: # This env file should be checked into source control
[dotenv][DEBUG] did not match key and value when parsing line 2: # This is the place for default values for all environments
[dotenv][DEBUG] did not match key and value when parsing line 3: # Values in `.env.local` and `.env.production` will override these values
[dotenv][DEBUG] "DATABASE_URL" is already defined in `process.env` and will not be overwritten
[dotenv][DEBUG] "SESSION_SECRET_KEY" is already defined in `process.env` and will not be overwritten
[dotenv][DEBUG] "DEBUG" is already defined in `process.env` and will not be overwritten
2021-03-26T13:17:25.762Z prisma:client clientVersion: 2.19.0
2021-03-26T13:17:25.796Z blitz:session Request has anonymousSessionToken
2021-03-26T13:17:25.798Z blitz:session Got existing session {
  handle: '-IbTzzuhRQb_l94THnKETNxXT1Uks8WF:ajwt',
  publicData: { userId: null },
  jwtPayload: {
    isAnonymous: true,
    handle: '-IbTzzuhRQb_l94THnKETNxXT1Uks8WF:ajwt',
    publicData: { userId: null },
    antiCSRFToken: 'HdgIwNPplI7D1aXKwDyVlWHbjOq0gxO3'
  },
  antiCSRFToken: 'HdgIwNPplI7D1aXKwDyVlWHbjOq0gxO3',
  anonymousSessionToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJibGl0empzIjp7ImlzQW5vbnltb3VzIjp0cnVlLCJoYW5kbGUiOiItSWJUenp1aFJRYl9sOTRUSG5LRVROeFhUMVVrczhXRjphand0IiwicHVibGljRGF0YSI6eyJ1c2VySWQiOm51bGx9LCJhbnRpQ1NSRlRva2VuIjoiSGRnSXdOUHBsSTdEMWFYS3dEeVZsV0hiak9xMGd4TzMifSwiaWF0IjoxNjE2NzYzOTc2LCJhdWQiOiJibGl0empzIiwiaXNzIjoiYmxpdHpqcyIsInN1YiI6ImFub255bW91cyJ9.9ISI9T7QMhwhvIkWkwUTLtRtov7VHQ6bpGR8Sx1mo-E'
}
2021-03-26 13:17:25.802 INFO signup() Starting with input: 
{
  email: 'test@live.fr',
  password: '[***]'
}
2021-03-26T13:17:25.824Z prisma:engine Search for Query Engine in /home/fragx1011/etudesnet/mono/node_modules/.prisma/client
2021-03-26T13:17:25.825Z plusX Execution permissions of /home/fragx1011/etudesnet/mono/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x are fine
2021-03-26T13:17:25.966Z prisma:client Prisma Client call:
2021-03-26T13:17:25.968Z prisma:client prisma.user.create({
  data: {
    email: 'test@live.fr',
    hashedPassword: 'JGFyZ29uMmlkJHY9MTkkbT02NTUzNix0PTIscD0xJGtmZFZlaUp6N2I0SmhBTVVGemZIdlEkUS96RDFBZ25TcUVQSUVUc1pMZFhEeWZZQ3lHUSsvQjBVRlhUZytPeVdrdwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
    role: 'USER'
  },
  select: {
    id: true,
    name: true,
    email: true,
    role: true
  }
})
2021-03-26T13:17:25.968Z prisma:client Generated request:
2021-03-26T13:17:25.968Z prisma:client mutation {
  createOneUser(data: {
    email: "test@live.fr"
    hashedPassword: "JGFyZ29uMmlkJHY9MTkkbT02NTUzNix0PTIscD0xJGtmZFZlaUp6N2I0SmhBTVVGemZIdlEkUS96RDFBZ25TcUVQSUVUc1pMZFhEeWZZQ3lHUSsvQjBVRlhUZytPeVdrdwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
    role: "USER"
  }) {
    id
    name
    email
    role
  }
}

2021-03-26T13:17:25.970Z prisma:engine { cwd: '/home/fragx1011/etudesnet/mono/db' }
2021-03-26T13:17:25.970Z prisma:engine Search for Query Engine in /home/fragx1011/etudesnet/mono/node_modules/.prisma/client
2021-03-26T13:17:25.970Z plusX Execution permissions of /home/fragx1011/etudesnet/mono/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x are fine
2021-03-26T13:17:25.971Z prisma:engine { flags: [ '--enable-raw-queries', '--port', '43025' ] }
2021-03-26T13:17:25.987Z prisma:engine stdout Starting a postgresql pool with 13 connections.
2021-03-26T13:17:26.016Z prisma:engine stdout Started http server on http://127.0.0.1:43025
2021-03-26T13:17:26.020Z prisma:engine Search for Query Engine in /home/fragx1011/etudesnet/mono/node_modules/.prisma/client
2021-03-26T13:17:26.021Z plusX Execution permissions of /home/fragx1011/etudesnet/mono/node_modules/.prisma/client/query-engine-debian-openssl-1.1.x are fine
2021-03-26T13:17:26.029Z prisma:engine {
  error: Error: connect ECONNREFUSED ::1:43025
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '::1',
    port: 43025
  }
}
2021-03-26T13:17:26.032Z prisma:engine {
  error: Error: connect ECONNREFUSED ::1:43025
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '::1',
    port: 43025
  }
}
2021-03-26T13:17:26.033Z prisma:engine Client Version: 2.19.0
2021-03-26T13:17:26.033Z prisma:engine Engine Version: query-engine c1455d0b443d66b0d9db9bcb1bb9ee0d5bbc511d
2021-03-26T13:17:26.033Z prisma:engine Active provider: postgresql
2021-03-26T13:17:26.033Z prisma:engine {
  error: Error: connect ECONNREFUSED ::1:43025
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '::1',
    port: 43025
  }
}
2021-03-26T13:17:26.033Z prisma:client Error: connect ECONNREFUSED ::1:43025
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
2021-03-26 13:17:26.034 ERROR signup() 
 Error  connect ECONNREFUSED ::1:43025
details:
{
  code: 'ECONNREFUSED',
  clientVersion: '2.19.0',
  meta: undefined
}
error stack:
• index.js:34774 cb
    node_modules/@prisma/client/runtime/index.js:34774:17

• signup.js:175 <anonymous>
    .next/server/pages/api/auth/mutations/signup.js:175:16

• blitzjs-core-server.cjs.prod.js:395 <anonymous>
    node_modules/@blitzjs/core/server/dist/blitzjs-core-server.cjs.prod.js:395:20

• blitzjs-core-server.cjs.prod.js:1619 <anonymous>
    node_modules/@blitzjs/core/server/dist/blitzjs-core-server.cjs.prod.js:1619:22

• blitzjs-core-server.cjs.prod.js:121 handleRequestWithMiddleware
    node_modules/@blitzjs/core/server/dist/blitzjs-core-server.cjs.prod.js:121:5

• api-utils.ts:86 apiResolver
    node_modules/next/next-server/server/api-utils.ts:86:5

• next-server.ts:1078 handleApiRequest
    node_modules/next/next-server/server/next-server.ts:1078:5

• next-server.ts:952 fn
    node_modules/next/next-server/server/next-server.ts:952:27

• router.ts:247 execute
    node_modules/next/next-server/server/router.ts:247:24

Paste all relevant code snippets here:

import { enhancePrisma } from "blitz"
import { PrismaClient } from "@prisma/client"

const EnhancedPrisma = enhancePrisma(PrismaClient)

export * from "@prisma/client"
export default new PrismaClient({ __internal: { useUds: true } } as any)
import { enhancePrisma } from "blitz"
import { PrismaClient } from "@prisma/client"

const EnhancedPrisma = enhancePrisma(PrismaClient)

export * from "@prisma/client"
export default new EnhancedPrisma({ __internal: { useUds: true } } as any)

What are detailed steps to reproduce this?

  1. clone the last version of blitz in archlinux with postgresql database, i think it more a prisma error

Run blitz -v and paste the output here:


Linux 5.10 | linux-x64 | Node: v14.16.0

blitz: 0.33.0 (global)
blitz: 0.33.0 (local)

  Package manager: yarn 
  System:
    OS: Linux 5.10 Manjaro Linux
    CPU: (12) x64 AMD Ryzen 5 2600 Six-Core Processor
    Memory: 1.06 GB / 15.62 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.16.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: ~2.19 => 2.19.0 
    blitz: 0.33.0 => 0.33.0 
    prisma: ~2.19 => 2.19.0 
    react: 0.0.0-experimental-3310209d0 => 0.0.0-experimental-3310209d0 
    react-dom: 0.0.0-experimental-3310209d0 => 0.0.0-experimental-3310209d0 
    typescript: ~4.1 => 4.1.5 
karimsx commented 3 years ago

fixed in case there is an error with prisma, you need to enable unix domain socket :

import { enhancePrisma } from "blitz"
import { PrismaClient } from "@prisma/client"

const EnhancedPrisma = enhancePrisma(PrismaClient)

export * from "@prisma/client"
export default new EnhancedPrisma({ __internal: { useUds: true } } as any)
hylerrix commented 3 years ago

fixed in case there is an error with prisma, you need to enable unix domain socket :

import { enhancePrisma } from "blitz"
import { PrismaClient } from "@prisma/client"

const EnhancedPrisma = enhancePrisma(PrismaClient)

export * from "@prisma/client"
export default new EnhancedPrisma({ __internal: { useUds: true } } as any)

Meet the same issue (blitz new app and then cannot sign up). Fixed it in your way, thx!

You are using beta software - if you have any problems, please open an issue here:
      https://github.com/blitz-js/blitz/issues/new/choose

macOS Big Sur | darwin-x64 | Node: v12.19.0

blitz: 0.34.0 (global)

  Package manager: npm 
  System:
    OS: macOS 11.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
    Memory: 17.48 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: Not Found
    blitz: Not Found
    prisma: Not Found
    react: Not Found
    react-dom: Not Found
    typescript: Not Found
hylerrix commented 3 years ago

But what can I do when I occur this issue just after sign up success...?

sign up / log out run well, but prisma studio ui cannot load data:

blitz prisma studio
Message: Error in Prisma Client request: 

Error: connect ECONNREFUSED ::1:64584
    at cb (/Users/didi/.cache/prisma/studio/dc8b5d1d/runtime/index.js:34862:17)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Query:
prisma.user.findMany({
  take: 100,
  skip: 0,
  select: {
    id: true,
    createdAt: true,
    updatedAt: true,
    name: true,
    email: true,
    hashedPassword: true,
    role: true,
    tokens: true,
    sessions: true,
  }
})

karimsx commented 3 years ago

@hylerrix, its the same problem, check if prisma studio have a command line option to enable unix socket domain, else you can use dbeaver(free and opensource) to explore database if you are on linux

hylerrix commented 3 years ago

@hylerrix, its the same problem, check if prisma studio have a command line option to enable unix socket domain, else you can use dbeaver(free and opensource) to explore database if you are on linux

OooK :)