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

[BUG]: after running a while, insert postgres db return: CONNECT_TIMEOUT #1770

Closed
guotie opened this issue Jan 8, 2024 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@guotie
Copy link

guotie commented Jan 8, 2024

What version of drizzle-orm are you using?

0.29.0

What version of drizzle-kit are you using?

0.20.6

Describe the Bug

After run a while, insert postsql db return:

error: write CONNECT_TIMEOUT 127.0.0.1:5432
 code: "CONNECT_TIMEOUT"

Expected behavior

No response

Environment & setup

No response

@guotie guotie added the bug Something isn't working label Jan 8, 2024
@guotie
Copy link
Author

guotie commented Jan 9, 2024

24 |     }, options.path ? {} : { port: port }
25 |   )
26 |   Error.captureStackTrace(error, connection)
27 |   return error
28 | }
29 | 
             ^
error: write CONNECT_TIMEOUT 127.0.0.1:5432
 code: "CONNECT_TIMEOUT"

      at connection (/node_modules/postgres/src/errors.js:29:9)
      at connectTimedOut (/node_modules/postgres/src/connection.js:626:5)
      at done (/node_modules/postgres/src/connection.js:1035:12)

@guotie
Copy link
Author

guotie commented Jan 11, 2024

I think this problem is the same with this:

porsager/postgres#738

And I use bun too.

@AndriiSherman
Copy link
Member

It's postgres.js driver bug, but I can leave this issue for any references

@calebbehayilu
Copy link

@guotie did find any solution?

@guotie
Copy link
Author

guotie commented May 27, 2024

porsager/postgres#738

the latest postgres driver seems solved.

@guotie guotie closed this as completed May 27, 2024
@gregory-krieger
Copy link

gregory-krieger commented Jun 29, 2024

Well, for me it wasn't solved, so I replaced this :

import "dotenv/config";

import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";

const connectionString = process.env.DATABASE_URL;

// Disable prefetch as it is not supported for "Transaction" pool mode
export const client = postgres(connectionString!, {
  prepare: false,
  ssl: false,
});
export const db = drizzle(client, { schema });

with this :

import "dotenv/config";
import { PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";

const connectionString = process.env.DATABASE_URL;

const drizzleClient = drizzle(
  postgres(connectionString!, {
    prepare: false,
  }),
  { schema },
);

declare global {
  var database: PostgresJsDatabase<typeof schema> | undefined;
}

export const db = global.database || drizzleClient;
if (process.env.NODE_ENV !== "production") global.database = db;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants