19428: Skip brand new sessions when pruning.
authorTom Clegg <tom@curii.com>
Mon, 29 Aug 2022 20:59:20 +0000 (16:59 -0400)
committerTom Clegg <tom@curii.com>
Tue, 30 Aug 2022 14:19:47 +0000 (10:19 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/keep-web/cache.go

index d5fdc4997ecee3c67d1cc8ea4003c2c1e3f6cac4..e10419f5dc538969b3fafd2894ab055270868ca4 100644 (file)
@@ -276,7 +276,7 @@ func (c *cache) pruneSessions() {
        now := time.Now()
        var size int64
        keys := c.sessions.Keys()
-       for _, token := range keys {
+       for idx, token := range keys {
                ent, ok := c.sessions.Peek(token)
                if !ok {
                        continue
@@ -284,6 +284,7 @@ func (c *cache) pruneSessions() {
                s := ent.(*cachedSession)
                if s.expire.Before(now) {
                        c.sessions.Remove(token)
+                       keys[idx] = ""
                        continue
                }
                if fs, ok := s.fs.Load().(arvados.CustomFileSystem); ok {
@@ -294,6 +295,12 @@ func (c *cache) pruneSessions() {
        // least frequently used entries (which Keys() returns last).
        for i := len(keys) - 1; i >= 0; i-- {
                token := keys[i]
+               if token == "" {
+                       // removed this session in the loop above;
+                       // don't prune it, even if it's already been
+                       // reinserted.
+                       continue
+               }
                if size <= c.cluster.Collections.WebDAVCache.MaxCollectionBytes/2 {
                        break
                }