diff --git a/lib/backend/firestore/firestorebk.go b/lib/backend/firestore/firestorebk.go index a60946e35770a..8fce65ab248ec 100644 --- a/lib/backend/firestore/firestorebk.go +++ b/lib/backend/firestore/firestorebk.go @@ -762,12 +762,23 @@ func (b *Backend) purgeExpiredDocuments() error { return b.clientContext.Err() case <-t.C: expiryTime := b.clock.Now().UTC().Unix() - docs, err := b.svc.Collection(b.CollectionName).Where(expiresDocProperty, "<=", expiryTime).Documents(b.clientContext).GetAll() + // Find all documents that have expired, but EXCLUDE + // any documents that do not have an expiry as indicated + // by a value of 0. + docs, err := b.svc.Collection(b.CollectionName). + Where(expiresDocProperty, "<=", expiryTime). + Where(expiresDocProperty, ">", 0). + Documents(b.clientContext). + GetAll() if err != nil { b.Logger.WithError(trail.FromGRPC(err)).Warn("Failed to get expired documents") continue } + if len(docs) == 0 { + continue + } + if err := b.deleteDocuments(docs); err != nil { return trace.Wrap(err) }