hasura / hasura/graphql-engine
Error when restarting hasura instance pointed to database pool connection when using prepared statements
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: 2.0.10-cloud.1
### Environment
Tested on Cloud, probably an issue on all platforms
### What is the expected behaviour?
Hasura should be able to connect to database connection pools.
Alternatively, if hasura expects to be connected directly to databases when using prepared statements, it should be documented.
### Keywords
Hasura, Cloud, Prepared Statement, Inconsistency, Digital Ocean, PGBouncer
### What is the current behaviour?
When a hasura instance that is connected to a database via a PGBouncer connection pool is restarted, the following errors will be shown in console and the instance enters an inconsistent state:

(error text for searchability)
```
{
"statement": "BEGIN ISOLATION LEVEL READ COMMITTED READ ONLY",
"prepared": true,
"error": {
"exec_status": "FatalError",
"hint": null,
"message": "prepared statement \"0\" already exists",
"status_code": "42P05",
"description": null
},
"arguments": []
}
```
### How to reproduce the issue?
1. Create a digital ocean postgres database
2. Create a connection pool for it. Use pool mode transaction, which is default & recomended
2. Create a hasura cloud project, and configure it to connect to the database via the connection pool.
3. Open console, and make a change that will cause the database connection to be re-established
4. (in my case I changed the environment variable to an invalid one that did not exists, then changed it back)
5. You will now see the error mentioned above
To the team: I have setup a project which has this issue and can provide access to it.
### Screenshots or Screencast


### Any possible solutions?
Connecting to the database directly solves the problem
### Can you identify the location in the source code where the problem exists?
The error seems to indicate that hasura is attempting to create a stored procedure that already exists.
This leads me to think that stored procedures outlive the hasura connection to the pgbouncer pool, and thus still exist when hasura re-establishes connection with the database.
I do not know if this is a bug of hasura, pgbouncer, or both.
Contributor guide
Assessment
This issue has not been assessed yet.