Skip to content

Commit

Permalink
handle duplicate locks existing during unlock phase (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes authored Aug 21, 2024
1 parent e665ca9 commit 1663902
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
14 changes: 4 additions & 10 deletions backend/locking/backend_locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,12 @@ func (lock BackendDBLock) Lock(lockId int, resource string) (bool, error) {
}

func (lock BackendDBLock) Unlock(resource string) (bool, error) {
theLock, err := models.DB.GetDiggerLock(resource)
// delete all locks that match this resource
l := models.DiggerLock{}
err := models.DB.GormDB.Where("resource=?", resource).Delete(&l).Error
if err != nil {
if err != nil {
return false, fmt.Errorf("could not get lock record: %v", err)
}
return false, fmt.Errorf("could not delete all locks: %v", err)
}

err = models.DB.DeleteDiggerLock(theLock)
if err != nil {
return false, fmt.Errorf("could not delete lock record: %v", err)
}

return true, nil
}

Expand Down
10 changes: 0 additions & 10 deletions backend/models/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,13 +1245,3 @@ func (db *Database) GetDiggerLock(resource string) (*DiggerLock, error) {
}
return lock, nil
}

func (db *Database) DeleteDiggerLock(lock *DiggerLock) error {
log.Printf("DeleteDiggerLock Deleting: %v, %v", lock.LockId, lock.Resource)
result := db.GormDB.Delete(lock)
if result.Error != nil {
return result.Error
}
log.Printf("DeleteDiggerLock %v %v has been deleted successfully\n", lock.LockId, lock.Resource)
return nil
}
1 change: 1 addition & 0 deletions libs/locking/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func reportLockingFailed(r reporting.Reporter, comment string) {
}

func (projectLock *PullRequestLock) verifyNoHangingLocks() (bool, error) {
// TODO: Also include CI type (github, gitlab etc. into this lockID in order to avoid collision across VCS)
lockId := projectLock.LockId()
transactionId, err := projectLock.InternalLock.GetLock(lockId)

Expand Down

0 comments on commit 1663902

Please sign in to comment.