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

Error with type 109 #430

Closed
nmime opened this issue Jul 19, 2022 · 20 comments
Closed

Error with type 109 #430

nmime opened this issue Jul 19, 2022 · 20 comments

Comments

@nmime
Copy link

nmime commented Jul 19, 2022

PostgresError: expected password response, got message type 109
Postgres can work and give it out at some stage
What could it be?

image

@porsager
Copy link
Owner

Interesting 😊 Could you supply some more details please?

@nmime
Copy link
Author

nmime commented Jul 20, 2022

I don't have more details.

I do about 10 selects and updates per second.
and get it

@porsager
Copy link
Owner

Connection details, Postgres.js version, PostgreSQL version, when does it happen, etc etc.

@nmime
Copy link
Author

nmime commented Jul 23, 2022

connection details postgres(URI)
PostgreSQL 14.4
Postgres.js 3.2.4
when i use postgres (select, update) and not always 😕
last time it was on query:

select count(*) from nfts
where collection = ADDRESS

@porsager
Copy link
Owner

porsager commented Jul 23, 2022

Ok good info - so everything works except sometimes you receive this error at random. Do you connect directly to a Postgres DB or is there something in between, eg pgbouncer?

What connection options do you run with?

@nmime
Copy link
Author

nmime commented Jul 23, 2022

Directly, I did not install anything other than postgresql itself.

@porsager
Copy link
Owner

porsager commented Aug 9, 2022

Do you have anything in you DB logs when this happens?

@porsager
Copy link
Owner

porsager commented Sep 4, 2022

Would love to check this out if you can create a reproducible sample. Let me know if that's possible and reopen if you're still experiencing this issue.

@porsager porsager closed this as completed Sep 4, 2022
@Lesiuk
Copy link

Lesiuk commented Jan 8, 2023

@NMIFUN @porsager I have the same issue.

@Lesiuk
Copy link

Lesiuk commented Jan 8, 2023

image

On my side It's not random. It always happens when I am doing the same query in parallel (multiple queries at the same time) .

@Lesiuk
Copy link

Lesiuk commented Jan 8, 2023

@porsager

deno 1.29.2, postgresql 11.7 run it few times, and you will get those errors

import { parallel, range } from 'npm:radash';
import postgres from 'https://deno.land/x/postgresjs/mod.js'

const sql = postgres('YOUR_URL');

await parallel(10, [...range(0, 100)], async () => {
    await sql`select 1;`; // select * from table is even better at reproducing it
})

image

@Lesiuk
Copy link

Lesiuk commented Jan 8, 2023

It works fine when connecting through pgbouncer.

@rlopzc
Copy link

rlopzc commented Apr 14, 2023

Hello @Lesiuk did you find a fix without pgouncer? We are having this same error in prod

@rlopzc
Copy link

rlopzc commented Apr 14, 2023

This are the logs for my error. 5 connections in parallel in the same second. @porsager could you reproduce with @Lesiuk provided code?

2023-04-14 11:19:46 UTC:42.982.123.5(6023):[unknown]@[unknown]:[12477]:LOG:  connection received: host=42.982.123.5 port=6023
2023-04-14 11:19:46 UTC:42.982.123.5(25172):[unknown]@[unknown]:[12478]:LOG:  connection received: host=42.982.123.5 port=25172
2023-04-14 11:19:46 UTC:42.982.123.5(20577):[unknown]@[unknown]:[12479]:LOG:  connection received: host=42.982.123.5 port=20577
2023-04-14 11:19:46 UTC:42.982.123.5(42886):[unknown]@[unknown]:[12481]:LOG:  connection received: host=42.982.123.5 port=42886
2023-04-14 11:19:46 UTC:42.982.123.5(51602):[unknown]@[unknown]:[12480]:LOG:  connection received: host=42.982.123.5 port=51602
2023-04-14 11:19:46 UTC:42.982.123.5(6023):user@test_db:[12477]:LOG:  connection authorized: user=user database=test_db application_name=postgres.js
2023-04-14 11:19:46 UTC:42.982.123.5(25172):user@test_db:[12478]:LOG:  connection authorized: user=user database=test_db application_name=postgres.js
2023-04-14 11:19:46 UTC:42.982.123.5(20577):user@test_db:[12479]:LOG:  connection authorized: user=user database=test_db application_name=postgres.js
2023-04-14 11:19:46 UTC:42.982.123.5(42886):user@test_db:[12481]:LOG:  connection authorized: user=user database=test_db application_name=postgres.js
2023-04-14 11:19:46 UTC:42.982.123.5(51602):user@test_db:[12480]:FATAL:  expected password response, got message type 109

@porsager
Copy link
Owner

Perhaps the error message is a red herring, and it is because of reaching a connection limit, and Postgres.js is missing integration for that specific case. I'll see if I can replicate something like that on my end.

@porsager porsager reopened this Apr 14, 2023
@porsager
Copy link
Owner

Hmm.. no, that correctly errors with PostgresError: sorry, too many clients already

@porsager porsager reopened this Apr 14, 2023
@porsager
Copy link
Owner

Sorry - I haven't had time to look at issues, but going through them now and testing this, I am unable replicate, also with the code above and same postgres + deno versions.

If anyone is up for making a completely reproducible setup I'd love to look into it, but until then I'm gonna close this out.

@masfahru
Copy link

Sorry - I haven't had time to look at issues, but going through them now and testing this, I am unable replicate, also with the code above and same postgres + deno versions.

If anyone is up for making a completely reproducible setup I'd love to look into it, but until then I'm gonna close this out.

Hi @porsager , i got the same error while trying to benchmark bun using techempower benchmark setup.

image

Techempower benchmark setup is using this flags to create Postgres docker image:

ENV POSTGRES_HOST_AUTH_METHOD=md5
ENV POSTGRES_INITDB_ARGS=--auth-host=md5

Steps to reproduce:

  1. Create postgres container using this command:
docker run --name test-postgres-image -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_INITDB_ARGS="--auth-host=md5" -e POSTGRES_HOST_AUTH_METHOD=md5 -p 5432:5432 -d postgres:15-bullseye
  1. Init bun project in a folder using bun init -y (install bun first if needed)
  2. Add postgres using cli bun add postgres
  3. Edit index.ts and change the content to this code
import postgres from 'postgres'

const sql = postgres({
  host: 'localhost',
  user: 'postgres',
  password: 'mysecretpassword',
  database: 'postgres',
})

const results = await Promise.all([...Array(150).keys()].map(async (id) => {
  return sql.begin(async sql => sql`select ${id};`)
}))
console.log(results)
  1. Run index.ts using cli bun run index.ts

Error:
image

  1. Edit index.ts with this code
import postgres from 'postgres'

const sql = postgres({
  host: 'localhost',
  user: 'postgres',
  password: 'mysecretpassword',
  database: 'postgres',
})

const results = await Promise.all([...Array(150).keys()].map(async (id) => {
  return sql`select ${id};`;
}))
console.log(results)
  1. Run index.ts again using cli bun run index.ts
    Error:
    image

Hopefully it can be fixed soon, thank you

@porsager
Copy link
Owner

@masfahru I think point 7 was fixed in cae4d97

About replication the md5 issue, I have no luck. Tried your steps precisely.

@porsager
Copy link
Owner

Yay ! I think I got it ! Just had to look at the damn code ;) Fix coming up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants