Introduction -:
This article addresses an issue encountered in Terraform Enterprise (TFE) when attempting to re-publish a private module to the private registry after it has been deleted. The error is specific to cases where the module has multiple versions, and users experience random failures during re-publishing attempts.
Problem -:
When a customer deletes a private module from the TFE registry and immediately attempts to re-publish it, some module versions intermittently fail to publish with the following error displayed 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 it is not specific to any single module version
Cause -:
This issue is caused by database deadlocks due to concurrent transactions. When a module with multiple versions is deleted and re-published immediately:
- Some of the older module versions may still be in the process of being cleaned up/deleted in the background.
- Simultaneously, the re-publishing jobs try to reinsert those same versions.
This may creates a dead lock situation in the PostgreSQL database, resulting in deadlock errors.
Logs from the support bundle will show details like:
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
Overview of possible solutions -:
This deadlock error is temporary and usually resolves itself upon retry.
Recommended steps:
-
If you encounter the error, wait 30–60 seconds and try publishing the module again.
-
To avoid the error altogether, after deleting a module from the registry:
-
Wait a few minutes before starting the re-publish process.
-
This allows all background deletion jobs to fully complete and release any locks in the database.
-
Following the above approach should ensure all module versions publish successfully without any failures.
Additional Information
-
This is a known issue and a bug report has already been submitted to HashiCorp Engineering . This article will be updated as soon as any fixes or any recommendation has been released from engineering .