Title: [177080] trunk/Source/WebCore
Revision
177080
Author
commit-qu...@webkit.org
Date
2014-12-10 10:54:26 -0800 (Wed, 10 Dec 2014)

Log Message

[Curl] Cache entry is sometimes deleted when request receives a not modified response.
https://bugs.webkit.org/show_bug.cgi?id=139339

Patch by pe...@outlook.com <pe...@outlook.com> on 2014-12-10
Reviewed by Alex Christensen.

Sometimes it happens that a request receives a not modified response,
but the cache entry has already been deleted by another request.
This can be avoided by locking a cache entry while there are pending
requests for the cache entry's url.

* platform/network/curl/CurlCacheEntry.h:
(WebCore::CurlCacheEntry::addClient):
(WebCore::CurlCacheEntry::removeClient):
(WebCore::CurlCacheEntry::hasClients):
* platform/network/curl/CurlCacheManager.cpp:
(WebCore::CurlCacheManager::didReceiveResponse):
(WebCore::CurlCacheManager::didFail):
(WebCore::CurlCacheManager::addCacheEntryClient):
(WebCore::CurlCacheManager::removeCacheEntryClient):
* platform/network/curl/CurlCacheManager.h:
* platform/network/curl/ResourceHandleManager.cpp:
(WebCore::isHttpNotModified):
(WebCore::headerCallback):
(WebCore::ResourceHandleManager::initializeHandle):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (177079 => 177080)


--- trunk/Source/WebCore/ChangeLog	2014-12-10 18:38:25 UTC (rev 177079)
+++ trunk/Source/WebCore/ChangeLog	2014-12-10 18:54:26 UTC (rev 177080)
@@ -1,3 +1,30 @@
+2014-12-10  pe...@outlook.com  <pe...@outlook.com>
+
+        [Curl] Cache entry is sometimes deleted when request receives a not modified response.
+        https://bugs.webkit.org/show_bug.cgi?id=139339
+
+        Reviewed by Alex Christensen.
+
+        Sometimes it happens that a request receives a not modified response,
+        but the cache entry has already been deleted by another request.
+        This can be avoided by locking a cache entry while there are pending
+        requests for the cache entry's url.
+
+        * platform/network/curl/CurlCacheEntry.h:
+        (WebCore::CurlCacheEntry::addClient):
+        (WebCore::CurlCacheEntry::removeClient):
+        (WebCore::CurlCacheEntry::hasClients):
+        * platform/network/curl/CurlCacheManager.cpp:
+        (WebCore::CurlCacheManager::didReceiveResponse):
+        (WebCore::CurlCacheManager::didFail):
+        (WebCore::CurlCacheManager::addCacheEntryClient):
+        (WebCore::CurlCacheManager::removeCacheEntryClient):
+        * platform/network/curl/CurlCacheManager.h:
+        * platform/network/curl/ResourceHandleManager.cpp:
+        (WebCore::isHttpNotModified):
+        (WebCore::headerCallback):
+        (WebCore::ResourceHandleManager::initializeHandle):
+
 2014-12-10  Sebastian Dröge  <sebast...@centricular.com>
 
         [GStreamer] Use a buffer pool for allocations in the AudioDestination

Modified: trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h (177079 => 177080)


--- trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h	2014-12-10 18:38:25 UTC (rev 177079)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheEntry.h	2014-12-10 18:54:26 UTC (rev 177080)
@@ -32,6 +32,8 @@
 #include "ResourceHandle.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
+#include <wtf/HashMap.h>
+#include <wtf/ListHashSet.h>
 #include <wtf/Vector.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
@@ -63,6 +65,10 @@
 
     void setIsLoading(bool);
 
+    void addClient(ResourceHandle* job) { m_clients.add(job); }
+    void removeClient(ResourceHandle* job) { m_clients.remove(job); }
+    int hasClients() const { return m_clients.size() > 0; }
+
     const ResourceHandle* getJob() const { return m_job; }
 
 private:
@@ -76,6 +82,7 @@
     double m_expireDate;
     bool m_headerParsed;
     bool m_isLoading;
+    ListHashSet<ResourceHandle*> m_clients;
 
     ResourceResponse m_cachedResponse;
     HTTPHeaderMap m_requestHeaders;

Modified: trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp (177079 => 177080)


--- trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp	2014-12-10 18:38:25 UTC (rev 177079)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheManager.cpp	2014-12-10 18:54:26 UTC (rev 177080)
@@ -204,13 +204,15 @@
 
     const String& url = ""
 
+    removeCacheEntryClient(url, &job);
+
     if (response.httpStatusCode() == 304) {
         readCachedData(url, &job, response);
         m_LRUEntryList.prependOrMoveToFirst(url);
     }
     else if (response.httpStatusCode() == 200) {
         auto it = m_index.find(url);
-        if (it != m_index.end() && it->value->isLoading())
+        if (it != m_index.end() && (it->value->isLoading() || it->value->hasClients()))
             return;
 
         invalidateCacheEntry(url); // Invalidate existing entry on 200
@@ -326,6 +328,26 @@
     invalidateCacheEntry(url);
 }
 
+void CurlCacheManager::addCacheEntryClient(const String& url, ResourceHandle* job)
+{
+    if (m_disabled)
+        return;
+
+    auto it = m_index.find(url);
+    if (it != m_index.end())
+        it->value->addClient(job);
+}
+
+void CurlCacheManager::removeCacheEntryClient(const String& url, ResourceHandle* job)
+{
+    if (m_disabled)
+        return;
+
+    auto it = m_index.find(url);
+    if (it != m_index.end())
+        it->value->removeClient(job);
+}
+
 void CurlCacheManager::readCachedData(const String& url, ResourceHandle* job, ResourceResponse& response)
 {
     if (m_disabled)

Modified: trunk/Source/WebCore/platform/network/curl/CurlCacheManager.h (177079 => 177080)


--- trunk/Source/WebCore/platform/network/curl/CurlCacheManager.h	2014-12-10 18:38:25 UTC (rev 177079)
+++ trunk/Source/WebCore/platform/network/curl/CurlCacheManager.h	2014-12-10 18:54:26 UTC (rev 177080)
@@ -54,6 +54,9 @@
     void didFinishLoading(ResourceHandle&);
     void didFail(ResourceHandle&);
 
+    void addCacheEntryClient(const String& url, ResourceHandle* job);
+    void removeCacheEntryClient(const String& url, ResourceHandle* job);
+
 private:
     CurlCacheManager();
     ~CurlCacheManager();

Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp (177079 => 177080)


--- trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp	2014-12-10 18:38:25 UTC (rev 177079)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp	2014-12-10 18:54:26 UTC (rev 177080)
@@ -228,6 +228,11 @@
     return statusCode == 401;
 }
 
+inline static bool isHttpNotModified(int statusCode)
+{
+    return statusCode == 304;
+}
+
 ResourceHandleManager::ResourceHandleManager()
     : m_downloadTimer(*this, &ResourceHandleManager::downloadTimerCallback)
     , m_cookieJarFileName(cookieJarPath())
@@ -546,7 +551,7 @@
         }
 
         if (client) {
-            if (httpCode == 304) {
+            if (isHttpNotModified(httpCode)) {
                 const String& url = ""
                 CurlCacheManager::getInstance().getCachedResponse(url, d->m_response);
             }
@@ -1081,6 +1086,7 @@
         HTTPHeaderMap customHeaders = job->firstRequest().httpHeaderFields();
 
         if (CurlCacheManager::getInstance().isCached(url)) {
+            CurlCacheManager::getInstance().addCacheEntryClient(url, job);
             HTTPHeaderMap& requestHeaders = CurlCacheManager::getInstance().requestHeaders(url);
 
             // append additional cache information
@@ -1090,6 +1096,10 @@
                 customHeaders.set(it->key, it->value);
                 ++it;
             }
+        } else {
+            // Make sure we don't send any cache headers when url is not cached.
+            customHeaders.remove(HTTPHeaderName::IfModifiedSince);
+            customHeaders.remove(HTTPHeaderName::IfNoneMatch);
         }
 
         HTTPHeaderMap::const_iterator end = customHeaders.end();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to