cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
4.06k stars 304 forks source link

Postgresql not compatible with `ON_ERROR_STOP` option #1431

Open autra opened 1 week ago

autra commented 1 week ago

Describe the bug When \set ON_ERROR_STOP 'on' is present on user's own psqlrc or in the initialScript, if an error happens on the script, devenv seems to loose track of the original postgresql pid

To reproduce

Please use this gist: https://gist.github.com/autra/647f30ed267c99681f19522010b0bf30

The logs are like this:

ERROR:  column "foo" does not exist
LINE 1: select foo;
               ^
Time: 0,071 ms 

PostgreSQL database directory appears to contain a database; Skipping initialization
2024-09-09 12:11:14.552 GMT [915180] FATAL:  lock file "postmaster.pid" already exists
2024-09-09 12:11:14.552 GMT [915180] HINT:  Is another postmaster (PID 915161) running in data directory "/home/augustin/repos/devenv_test_cases/.devenv/state/postgres"? 

PostgreSQL database directory appears to contain a database; Skipping initialization

2024-09-09 12:11:15.604 GMT [915189] FATAL:  lock file "postmaster.pid" already exists
2024-09-09 12:11:15.604 GMT [915189] HINT:  Is another postmaster (PID 915161) running in data directory "/home/augustin/repos/devenv_test_cases/.devenv/state/postgres"?

PostgreSQL database directory appears to contain a database; Skipping initialization

2024-09-09 12:11:16.655 GMT [915196] FATAL:  lock file "postmaster.pid" already exists
2024-09-09 12:11:16.655 GMT [915196] HINT:  Is another postmaster (PID 915161) running in data directory "/home/augustin/repos/devenv_test_cases/.devenv/state/postgres"?

Then, the last 5 lines are looping constantly.

If I type f9, process-compose exits, but the original postgres process still runs in the background.

Version

devenv 1.0.5 (x86_64-linux)

autra commented 1 week ago

ON_ERROR_STOP changes the behaviour of psql. By default, a scripting error still causes psql to complete successfully with error code 0. With ON_ERROR_STOP to "on", psql stops at the first error and returns 3.

It seems that this behaviour somehow makes devenv try to start another postgresql.

While this bug is about not loosing track of postgres's pid if psql fails for some reason, I'd also argue that ON_ERROR_STOP should actually be the default in the context of devenv.

autra commented 1 week ago

Edited to add one precision

If I type f9, process-compose exits, but the original postgres process still runs in the background.