Open bidipeppercrap opened 8 months ago
Have you found solution?
Same problem with nextjs node or bun doesn't matter
Same problem with nextjs node or bun doesn't matter
I found it worked with Node
Only in Deno it is not working.
Same problem with nextjs node or bun doesn't matter
I found it worked with Next.js Typescript
Only in Deno it is not working.
It's working in production I guess but on dev it can work for a while but then on hot reload this error happens
Same problem with nextjs node or bun doesn't matter
I found it worked with Next.js Typescript Only in Deno it is not working.
It's working in production I guess but on dev it can work for a while but then on hot reload this error happens
This is a matter of migrating
It worked with Node or npm run migrate...
But doesn't work with deno task migrate...
I'm having this issue when reserving but not with regular connections. @porsager could really use your help here.
const admin = pg(databaseUrl, { database: "postgres" })
return {
admin: await admin.reserve()
}
Crashes:
node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js:389
stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
^
TypeError: Cannot read properties of undefined (reading 'replace')
Heads up that doing
await admin.unsafe("SELECT 1")
Solved the issue for me.
The problem occurs when I open my Mac after a couple of hours. This is a bug in error handling routine and obscures the real error. 100% should be fixed in this package.
file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:389
stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
^
TypeError: Cannot read properties of undefined (reading 'replace')
at queryError (file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:389:48)
at errored (file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:383:14)
at Socket.data (file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:318:9)
at Socket.emit (node:events:514:28)
at Socket.emit (node:domain:488:12)
at addChunk (node:internal/streams/readable:376:12)
at readableAddChunk (node:internal/streams/readable:349:9)
at Readable.push (node:internal/streams/readable:286:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Node.js v20.9.0
npm ERR! Lifecycle script `dev` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: backend@1.0.0
npm ERR! at location: /Users/epi/projects/hs4/packages/backend
Found the offending line:
Query:
{
reserve: [Function (anonymous)],
state: { pid: 17618, secret: 131674580 },
active: true
}
Error:
TypeError: Cannot read properties of undefined (reading '0')
at build (file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:223:42)
at execute (file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:167:7)
at ReadyForQuery (file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:568:27)
at handle (file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:503:6)
at Socket.data (file:///Users/epi/projects/hs4/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at Socket.emit (node:domain:488:12)
at addChunk (node:internal/streams/readable:376:12)
at readableAddChunk (node:internal/streams/readable:349:9)
at Readable.push (node:internal/streams/readable:286:10)
We saw this issue as well in our production environments after starting to use kysely-postgres-js.
We managed to track it down to the fact that initial
is sometimes set to true
and sometime to a query, it also seems to be true
more frequently when reserving connections using reserve()
. This is what kysely-postgres-js does under the hood, and also when @divmgl saw it. The current "workaround" is to use the suggestion from @divmgl and add a await sql.unsafe('SELECT 1')
before the connection is reserved. By doing this we get the actual error message.
The minimal code to reproduce this issue is to run the code below while your postgres instance is shutting down;
const sql = postgres({
...
});
const reserved = await sql.reserve();
await reserved.unsafe('SELECT 1');
initial
could potentially be set to true here;
https://github.com/porsager/postgres/blob/f58cd4f3affd3e8ce8f53e42799672d86cd2c70b/src/connection.js#L108-L114
But expected to be a query here; https://github.com/porsager/postgres/blob/f58cd4f3affd3e8ce8f53e42799672d86cd2c70b/src/connection.js#L384-L397
When running the reproduction code above, we could see that query=true
in queryError(query, err) { ... }
To replicate the problem:
.reserve()
.The error is shadowed with another one throwing in postgres/src/connection.js
because query
is true
instead of actual query.
+ query.origin.replace(/.*\n/, '\n')
Spec
Runtime: Deno Database Provider: Neon
Reproduce:
I run into this error when I try to migrate.
Code
deno.json
migrator:
db instance: