Skip to content

Commit 328faec

Browse files
modular-magicianChris Tomlinson
andauthored
Add mutex to compute_project_metadata_item (#4778) (#3262)
Co-authored-by: Chris Tomlinson <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Chris Tomlinson <[email protected]>
1 parent 1cd7edf commit 328faec

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

.changelog/4778.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: added mutex in `google_compute_metadata_item` to reduce retries + quota errors
3+
```

google-beta/resource_compute_project_metadata_item.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta inter
170170

171171
func updateComputeCommonInstanceMetadata(config *Config, projectID, key, userAgent string, afterVal *string, timeout time.Duration, failIfPresent metadataPresentBehavior) error {
172172
updateMD := func() error {
173+
lockName := fmt.Sprintf("projects/%s/commoninstancemetadata", projectID)
174+
mutexKV.Lock(lockName)
175+
defer mutexKV.Unlock(lockName)
176+
173177
log.Printf("[DEBUG] Loading project metadata: %s", projectID)
174178
project, err := config.NewComputeClient(userAgent).Projects.Get(projectID).Do()
175179
if err != nil {

0 commit comments

Comments
 (0)