steebchen / prisma-client-go

Prisma Client Go is an auto-generated and fully type-safe database client
https://goprisma.org
Apache License 2.0
2.02k stars 96 forks source link

CockroachDB connection failed: "spawn: query engine errored" #1228

Open jy5275 opened 3 months ago

jy5275 commented 3 months ago

Version

github.com/steebchen/prisma-client-go v0.35.0

Problem Description

I tried to use Go Prisma to connect my local single node CockroachDB in a demo

func TestConn(t *testing.T) {
    client := db.NewClient()
    err := client.Prisma.Connect()
    assert.NoError(t, err)
    defer client.Prisma.Disconnect()
}

But always got error on Connect()(100% reproducible): spawn: query engine errored: expected value at line 1 column 1

However, I can successfully pull exsiting table schema from CockroachDB by go run github.com/steebchen/prisma-client-go db pull.

Related Issue

I found issue 1128 reported the same problem. Its solution was to use a fix version go get github.com/steebchen/prisma-client-go@a10327f06445dd9aa8edd63759ef253caf491541. But that version didn't work for me, with the same error message.

Logs

Full log with PRISMA_CLIENT_GO_LOG=debug set:

[prisma-client-go] DEBUG: 2024/03/27 12:49:09.868741 temp dir: /tmp
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.868788 query engine exists, not unpacking. 49.024µs. at /tmp/prisma/binaries/engines/0ca5ccbcfa6bdc81c003cf549abe4269f59c41e5/unpacked/v2/prisma-query-engine-debian-openssl-3.0.x
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.868898 ensure query engine binary...
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.868935 temp dir: /tmp
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.868957 global cache dir: /home/ubuntu/.cache
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.874228 checking for local query engine `prisma-query-engine-linux-static-x64` or `prisma-query-engine-debian-openssl-3.0.x`
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.874250 checking for global query engine `/tmp/prisma/binaries/engines/5a9203d0590c951969e85a7d07215503f4672eb9/unpacked/v2/prisma-query-engine-linux-static-x64` or `/tmp/prisma/binaries/engines/5a9203d0590c951969e85a7d07215503f4672eb9/unpacked/v2/prisma-query-engine-debian-openssl-3.0.x`
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.874262 checking for cached query engine `/home/ubuntu/.cache/prisma/binaries/cli/5.10.2/5a9203d0590c951969e85a7d07215503f4672eb9/prisma-query-engine-linux-static-x64` or `/home/ubuntu/.cache/prisma/binaries/cli/5.10.2/5a9203d0590c951969e85a7d07215503f4672eb9/prisma-query-engine-debian-openssl-3.0.x`
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.874689 exact query engine found in cache path: /home/ubuntu/.cache/prisma/binaries/cli/5.10.2/5a9203d0590c951969e85a7d07215503f4672eb9/prisma-query-engine-linux-static-x64 &{name:prisma-query-engine-linux-static-x64 size:22861456 mode:493 modTime:{wall:191010872 ext:63847114860 loc:0x1a5e1e0} sys:{Dev:2064 Ino:109207 Nlink:1 Mode:33261 Uid:1000 Gid:1000 X__pad0:0 Rdev:0 Size:22861456 Blksize:4096 Blocks:44656 Atim:{Sec:1711518061 Nsec:811010660} Mtim:{Sec:1711518060 Nsec:191010872} Ctim:{Sec:1711518060 Nsec:191010872} X__unused:[0 0 0]}}
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.889956 version check took 15.1788ms
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.890015 using query engine at /home/ubuntu/.cache/prisma/binaries/cli/5.10.2/5a9203d0590c951969e85a7d07215503f4672eb9/prisma-query-engine-linux-static-x64
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.890021 ensure query engine took 21.086237ms
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.891006 running query-engine on port 37489
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.891152 starting engine...
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.891386 connecting to engine...
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.891479 prisma engine payload: `{}`
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.892378 could not connect; retrying...
{"timestamp":"2024-03-27T05:49:09.901295Z","level":"INFO","fields":{"message":"Encountered error during initialization:"},"target":"query_engine"}
2024/03/27 12:49:09 expected value at line 1 column 1
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.993222 disconnecting...
[prisma-client-go] DEBUG: 2024/03/27 12:49:09.993247 query engine closed
--- FAIL: TestConn (0.12s)
    bench_test.go:13: 
                Error Trace:    ...
                Error:          Received unexpected error:
                                spawn: query engine errored: expected value at line 1 column 1
                Test:           TestConn
FAIL
steebchen commented 3 months ago

Can you share your URL string please if possible? Or can you try encoding the password in the DB string using encodeURIComponent()?

jy5275 commented 2 months ago

Can you share your URL string please if possible? Or can you try encoding the password in the DB string using encodeURIComponent()?

 datasource db {
  provider = "cockroachdb"
  url      = "postgres://root@localhost:26257/defaultdb?sslmode=disable"
}

This is a local deployed CockroachDB by cockroach start-single-node --insecure

steebchen commented 2 months ago

That error message looks like https://github.com/prisma/prisma-engines/issues/4613 which is still unclear why it happens. Can you maybe try using url = ENV("DATABASE_URL") and setting the connection string with the DATABASE_URL env? Just to see if it is related to this bug or something different

also please set PRISMA_CLIENT_GO_LOG=debug and check if there are any other errors?

jy5275 commented 2 months ago

@steebchen Thanks. The connection succeed with url = ENV("DATABASE_URL"). Debug log:

[prisma-client-go] DEBUG: 2024/04/15 16:38:43.092567 temp dir: /tmp
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.092619 query engine exists, not unpacking. 54.494µs. at /tmp/prisma/binaries/engines/473ed3124229e22d881cb7addf559799debae1ab/unpacked/v2/prisma-query-engine-debian-openssl-3.0.x
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.092752 ensure query engine binary...
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.092784 temp dir: /tmp
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.092808 global cache dir: /home/ubuntu/.cache
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.096261 checking for local query engine `prisma-query-engine-linux-static-x64` or `prisma-query-engine-debian-openssl-3.0.x`
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.096294 checking for global query engine `/tmp/prisma/binaries/engines/473ed3124229e22d881cb7addf559799debae1ab/unpacked/v2/prisma-query-engine-linux-static-x64` or `/tmp/prisma/binaries/engines/473ed3124229e22d881cb7addf559799debae1ab/unpacked/v2/prisma-query-engine-debian-openssl-3.0.x`
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.096561 checking for cached query engine `/home/ubuntu/.cache/prisma/binaries/cli/5.12.0/473ed3124229e22d881cb7addf559799debae1ab/prisma-query-engine-linux-static-x64` or `/home/ubuntu/.cache/prisma/binaries/cli/5.12.0/473ed3124229e22d881cb7addf559799debae1ab/prisma-query-engine-debian-openssl-3.0.x`
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.096607 query engine found in cache path: /home/ubuntu/.cache/prisma/binaries/cli/5.12.0/473ed3124229e22d881cb7addf559799debae1ab/prisma-query-engine-debian-openssl-3.0.x &{name:prisma-query-engine-debian-openssl-3.0.x size:18388392 mode:493 modTime:{wall:566250604 ext:63848770587 loc:0x1b2d420} sys:{Dev:2064 Ino:287657 Nlink:1 Mode:33261 Uid:1000 Gid:1000 X__pad0:0 Rdev:0 Size:18388392 Blksize:4096 Blocks:35920 Atim:{Sec:1713173787 Nsec:666250599} Mtim:{Sec:1713173787 Nsec:566250604} Ctim:{Sec:1713173787 Nsec:566250604} X__unused:[0 0 0]}}
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.101492 version check took 4.831323ms
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.101524 using query engine at /home/ubuntu/.cache/prisma/binaries/cli/5.12.0/473ed3124229e22d881cb7addf559799debae1ab/prisma-query-engine-debian-openssl-3.0.x
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.101582 ensure query engine took 8.798098ms
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.102846 running query-engine on port 39263
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.103023 starting engine...
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.103364 connecting to engine...
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.103403 prisma engine payload: `{}`
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.104329 could not connect; retrying...
{"timestamp":"2024-04-15T09:38:43.109840Z","level":"INFO","fields":{"message":"Starting a postgresql pool with 17 connections."},"target":"quaint::pooled"}
{"timestamp":"2024-04-15T09:38:43.140801Z","level":"INFO","fields":{"message":"Started query engine http server on http://127.0.0.1:39263","ip":"127.0.0.1","port":"39263"},"target":"query_engine::server"}
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.204575 prisma engine payload: `{}`
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.206343 [timing] query engine raw request took 1.694211ms
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.206414 prisma engine response: `{"status":"ok"}`
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.206436 [timing] elapsed: 9µs
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.206462 [timing] just http: 1.685211ms
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.206471 [timing] http percentage: 99.47%
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.206503 connecting took 113.719797ms
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.206518 connected.
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.206522 disconnecting...
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.208226 disconnected.
[prisma-client-go] DEBUG: 2024/04/15 16:38:43.208244 query engine closed
PASS
ok      CR-Prisma  0.118s
steebchen commented 2 months ago

Awesome thanks. I still have to figure out the actual error but at least you got it working for now