Open gorpher opened 4 years ago
Hi @gorpher, I'm not sure when exactly you would like to close this Close()
method, it seems like you would like Terraform to call it at the end of the Terraform run, but the connection is already closed when Terraform exit is it not?
Hi @gorpher, thank you for raising this issue some time ago.
I'm trying to understand why we aren't calling close, it seems that db.Close()
would close the database connection immediately after setup, making the connection unusable for any subsequent database operations in the backend (e.g. locking, unlocking). When we initialize the connection, it’s solely to set up the database and return the connection for future use. Closing it at this point would prevent any further interactions with the database, resulting in runtime errors.
Instead, db.Close()
should only be called once we know the database connection is no longer needed. Ideally, this would be in a dedicated function or lifecycle step when the backend is finished doing backend work. Extending the backend base functionalities to handle this would be a significant effort, especially as I don’t see any reason to implement a Close method in the other backends, which could potentially impact them as well.
Current Terraform Version
Use-cases
if use terraform cli more than 100 at the same time with pgbackend postgress connenction number limit,terraform execution exception
Attempted Solutions
Proposal
I think terraform should added backend close function for second development
References
kinds of backend implement backend/backend.go , but this interface add close method ,It's against the principle of development, i holp terraform may expose pgbackend close function.