]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/Transients.cc
Bug 5051: Some collapsed revalidation responses never expire (#652)
[thirdparty/squid.git] / src / Transients.cc
index 4394ae98926f494d7c7031f1ff468a948653d3c6..235cfb7511df85348334605b253a1d109b12396e 100644 (file)
@@ -162,13 +162,26 @@ Transients::get(const cache_key *key)
         return nullptr;
     }
 
+    // store hadWriter before checking ENTRY_REQUIRES_COLLAPSING to avoid racing
+    // the writer that clears that flag and then leaves
+    const auto hadWriter = map->peekAtWriter(index);
+    if (!hadWriter && EBIT_TEST(anchor->basics.flags, ENTRY_REQUIRES_COLLAPSING)) {
+        debugs(20, 3, "not joining abandoned entry " << index);
+        map->closeForReadingAndFreeIdle(index);
+        return nullptr;
+    }
+
     StoreEntry *e = new StoreEntry();
     e->createMemObject();
     e->mem_obj->xitTable.index = index;
     e->mem_obj->xitTable.io = Store::ioReading;
     anchor->exportInto(*e);
-    const bool collapsingRequired = EBIT_TEST(anchor->basics.flags, ENTRY_REQUIRES_COLLAPSING);
-    e->setCollapsingRequirement(collapsingRequired);
+
+    if (EBIT_TEST(anchor->basics.flags, ENTRY_REQUIRES_COLLAPSING)) {
+        assert(hadWriter);
+        e->setCollapsingRequirement(true);
+    }
+
     // keep read lock to receive updates from others
     return e;
 }