Merge pull request #1648 from AdamMagued/fix/issue-1619-snapshots-async-lock

fix(api): handle concurrent snapshot deletion during list endpoint
This commit is contained in:
André Roth authored and GitHub committed 2026-10-31 20:06:28 +01:00
commit bc0fe9c0b7
2 files changed
+16

No files matched your search

+3
View File
@@ -36,6 +36,9 @@ func apiSnapshotsList(c *gin.Context) {
err := collection.ForEachSorted(SortMethodString, func(snapshot *deb.Snapshot) error {
err := collection.LoadComplete(snapshot)
if err != nil {
if err == database.ErrNotFound {
return nil
}
return err
}
+13
View File
@@ -51,3 +51,16 @@ func (s *SnapshotsSuite) TestGetSnapshotsReturns500OnCorruptRefList(c *C) {
c.Assert(response.Code, Equals, 500)
c.Assert(response.Body.String(), Matches, ".*msgpack.*|.*decode.*")
}
func (s *SnapshotsSuite) TestGetSnapshotsHandlesConcurrentDeletion(c *C) {
collection := s.context.NewCollectionFactory().SnapshotCollection()
snapshot := deb.NewSnapshotFromRefList("deleted-snapshot-list", nil, makePackageRefList(c), "")
c.Assert(collection.Add(snapshot), IsNil)
// Simulate concurrent deletion by dropping the ref key or entire snapshot record
c.Assert(collection.Drop(snapshot), IsNil)
response, err := s.HTTPRequest("GET", "/api/snapshots", nil)
c.Assert(err, IsNil)
c.Assert(response.Code, Equals, 200)
}