PostgREST / postgrest

REST API for any Postgres database
https://postgrest.org
MIT License
22.65k stars 1k forks source link

postgrest fails with error "failed: fe_sendauth: no password supplied" #2895

Open taimoorzaeem opened 10 months ago

taimoorzaeem commented 10 months ago

Environment

Description of issue

postgrest-test-io fails locally with the following error:

=========================== short test summary info ===========================
FAILED test/io/test_cli.py::test_cli[dump config] - test_cli.PostgrestError
FAILED test/io/test_cli.py::test_cli[no config] - test_cli.PostgrestError
FAILED test/io/test_cli.py::test_expected_config[aliases.config] - test_cli.PostgrestError
FAILED test/io/test_cli.py::test_expected_config[boolean-string.config] - test_cli.PostgrestError
FAILED test/io/test_cli.py::test_expected_config[boolean-numeric.config] - test_cli.PostgrestError
FAILED test/io/test_cli.py::test_expected_config[types.config] - test_cli.PostgrestError
================== 6 failed, 119 passed, 2 skipped in 35.21s ==================
Temporary directory kept at: /run/user/1000/postgrest/postgrest-with-postgresql-15-aYl

All the 6 errors messages are same as:

---------------------------- Captured stderr call -----------------------------
07/Aug/2023:11:06:27 +0500: An error ocurred when trying to query database settings for the config parameters
07/Aug/2023:11:06:27 +0500: {"code":"PGRST000","details":"connection to server on socket \"/run/postgresql/.s.PGSQL.5432\" failed: fe_sendauth: no password supplied\n","hint":null,"message":"Database connection error. Retrying the connection."}
07/Aug/2023:11:06:27 +0500: connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: fe_sendauth: no password supplied

postgrest: thread killed
taimoorzaeem commented 10 months ago

@steve-chavez Strangely, after #2897 postgrest-test-io is not failing anymore. All io-tests are passing now.

steve-chavez commented 10 months ago

@taimoorzaeem Hm, so judging by the error you reported it doesn't seem related to https://github.com/PostgREST/postgrest/issues/2896. I was thinking #2897 might have made the db config query faster but some quick testing indicates that in fact it got slower (with the join I added). So strange indeed.

taimoorzaeem commented 10 months ago

@steve-chavez Ahh, finally got it. The errors are gone because I stopped my locally installed postgresql server running on port 5432. After running systemctl stop postgresql, the errors got fixed. However if I start the server again my systemctl start postgresql, all of the 6 errors come up again.

steve-chavez commented 10 months ago

Good to know!

Now postgrest-test-io should always run against our sandboxed pg. Hm, there must be something wrong with its connection string.

wolfgangwalther commented 1 month ago

This is not a problem with our tests... it's actually a bug in PostgREST. The relevant IO tests mentioned above try to connect by default - but that's not a problem. As long as postgrest doesn't die, but retries, those errors will be logged on the console, but won't be a problem.

But in this specific case, the pg_hba.conf file is set to allow md5 authentication only - and no password is supplied. This then causes the fe_sendauth: no password supplied error, which we are not able to handle gracefully. In this case PostgREST just dies. The log output is like this on the latest main branch:

% postgrest-run
09/May/2024:16:00:12 +0200: Starting PostgREST 12.1 (a427fb6)...
09/May/2024:16:00:12 +0200: Attempting to connect to the database...
09/May/2024:16:00:12 +0200: {"code":"PGRST000","details":"connection to server on socket \"/run/postgresql/.s.PGSQL.5432\" failed: fe_sendauth: no password supplied\n","hint":null,"message":"Database connection error. Retrying the connection."}
09/May/2024:16:00:12 +0200: {"code":"PGRST000","details":"connection to server on socket \"/run/postgresql/.s.PGSQL.5432\" failed: fe_sendauth: no password supplied\n","hint":null,"message":"Database connection error. Retrying the connection."}
09/May/2024:16:00:12 +0200: Fatal error encountered. connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: fe_sendauth: no password supplied

postgrest: thread killed

Note, this is not even the io tests, but just a plain postgrest-run. I have postgres running on the default port, but needed to change the pg_hba.conf file to allow md5 instead of trust authentication from localhost.