Problem
When you delete a private module with multiple versions from the Terraform Enterprise (TFE) registry and immediately attempt to republish it, some module versions may intermittently fail to publish with the following error in the TFE UI:
Error: 1 error occurred: * ERROR: deadlock detected (SQLSTATE 40P01)
Each retry may show different versions failing with the same error, indicating the failure is not specific to any single module version.
Cause
This issue is caused by database deadlocks that occur from concurrent transactions in the PostgreSQL database. When you delete and then immediately republish a module with multiple versions, two processes conflict:
- Background jobs are still cleaning up and deleting the old module versions.
- The new publishing jobs attempt to reinsert the same versions that are being deleted.
This conflict creates a deadlock, resulting in the SQLSTATE 40P01 error. Logs from a support bundle may show details similar to the following output.
ERROR: deadlock detected (SQLSTATE 40P01)\n\n, Detail: Process 654 waits for ShareLock on transaction 44434988; blocked by process 653.\nProcess 653 waits for ShareLock on transaction 44434999; blocked by process 661.\nProcess 661 waits for ExclusiveLock on tuple (16,16) of relation 16557 of database 16467; blocked by process 654.","stack":"github.com/hashicorp/go-hclog.Stacktrace\n\t/go/pkg/mod/github.com/hashicorp/REDACTED@REDACTED/stacktrace.go:51\ngithub.com/has
Solutions
Solution 1: Wait and Retry
If you encounter the error, wait 30–60 seconds and then attempt to publish the module again. The deadlock is often temporary and resolves itself after a short period.
Solution 2: Wait Before Republishing
To prevent the error from occurring, wait several minutes after deleting a module from the registry before you attempt to republish it. This delay allows the background deletion jobs to complete and release any database locks, ensuring all module versions publish successfully.
Additional Information
This is a known issue, and a bug report has been submitted to HashiCorp Engineering (Reference: Bug ID IPL-7896). This article will be updated when engineering provides a resolution or recommended workaround.