Title: [184901] trunk/Source/WebKit2
Revision
184901
Author
[email protected]
Date
2015-05-27 01:37:20 -0700 (Wed, 27 May 2015)

Log Message

[SOUP] Network Cache: Handle the case when we fail to create the IO stream
https://bugs.webkit.org/show_bug.cgi?id=145406

Reviewed by Sergio Villar Senin.

We were asserting in that case, but it can happen that we
fail to create the stream. It happened to me after r184690, that
changed the NetworkCache::Key hash. Since this was not expected to
happen, the async operation never finished and the completion
handler never called, leaving resources loading forever. We
should make sure we call the completion handler with an error
code, so that the load finishes and the entry is silently removed
from the cache.

* NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
(WebKit::NetworkCache::IOChannel::read):
(WebKit::NetworkCache::IOChannel::readSync):
(WebKit::NetworkCache::IOChannel::write):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (184900 => 184901)


--- trunk/Source/WebKit2/ChangeLog	2015-05-27 07:23:49 UTC (rev 184900)
+++ trunk/Source/WebKit2/ChangeLog	2015-05-27 08:37:20 UTC (rev 184901)
@@ -1,3 +1,24 @@
+2015-05-27  Carlos Garcia Campos  <[email protected]>
+
+        [SOUP] Network Cache: Handle the case when we fail to create the IO stream
+        https://bugs.webkit.org/show_bug.cgi?id=145406
+
+        Reviewed by Sergio Villar Senin.
+
+        We were asserting in that case, but it can happen that we
+        fail to create the stream. It happened to me after r184690, that
+        changed the NetworkCache::Key hash. Since this was not expected to
+        happen, the async operation never finished and the completion
+        handler never called, leaving resources loading forever. We
+        should make sure we call the completion handler with an error
+        code, so that the load finishes and the entry is silently removed
+        from the cache.
+
+        * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
+        (WebKit::NetworkCache::IOChannel::read):
+        (WebKit::NetworkCache::IOChannel::readSync):
+        (WebKit::NetworkCache::IOChannel::write):
+
 2015-05-26  Carlos Garcia Campos  <[email protected]>
 
         Network Cache: Add cache capacity to the totals of JSON file

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp (184900 => 184901)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp	2015-05-27 07:23:49 UTC (rev 184900)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp	2015-05-27 08:37:20 UTC (rev 184901)
@@ -48,7 +48,6 @@
     case Type::Create: {
         g_file_delete(file.get(), nullptr, nullptr);
         m_outputStream = adoptGRef(G_OUTPUT_STREAM(g_file_create(file.get(), static_cast<GFileCreateFlags>(G_FILE_CREATE_PRIVATE), nullptr, nullptr)));
-        ASSERT(m_outputStream);
 #if !HAVE(STAT_BIRTHTIME)
         GUniquePtr<char> birthtimeString(g_strdup_printf("%" G_GUINT64_FORMAT, std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())));
         g_file_set_attribute_string(file.get(), "xattr::birthtime", birthtimeString.get(), G_FILE_QUERY_INFO_NONE, nullptr, nullptr);
@@ -57,12 +56,10 @@
     }
     case Type::Write: {
         m_ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr));
-        ASSERT(m_ioStream);
         break;
     }
     case Type::Read:
         m_inputStream = adoptGRef(G_INPUT_STREAM(g_file_read(file.get(), nullptr, nullptr)));
-        ASSERT(m_inputStream);
         break;
     }
 }
@@ -142,7 +139,11 @@
 
 void IOChannel::read(size_t offset, size_t size, std::function<void (Data&, int error)> completionHandler)
 {
-    ASSERT(m_inputStream);
+    if (!m_inputStream) {
+        Data data;
+        completionHandler(data, -1);
+        return;
+    }
 
     size_t bufferSize = std::min(size, gDefaultReadBufferSize);
     uint8_t* bufferData = static_cast<uint8_t*>(fastMalloc(bufferSize));
@@ -165,7 +166,12 @@
 // FIXME: It would be better to do without this.
 void IOChannel::readSync(size_t offset, size_t size, std::function<void (Data&, int error)> completionHandler)
 {
-    ASSERT(m_inputStream);
+    if (!m_inputStream) {
+        Data data;
+        completionHandler(data, -1);
+        return;
+    }
+
     size_t bufferSize = std::min(size, gDefaultReadBufferSize);
     uint8_t* bufferData = static_cast<uint8_t*>(fastMalloc(bufferSize));
     GRefPtr<SoupBuffer> readBuffer = adoptGRef(soup_buffer_new_with_owner(bufferData, bufferSize, bufferData, fastFree));
@@ -237,9 +243,17 @@
 
 void IOChannel::write(size_t offset, const Data& data, std::function<void (int error)> completionHandler)
 {
-    ASSERT(m_outputStream || m_ioStream);
+    if (!m_outputStream && !m_ioStream) {
+        completionHandler(-1);
+        return;
+    }
 
     GOutputStream* stream = m_outputStream ? m_outputStream.get() : g_io_stream_get_output_stream(G_IO_STREAM(m_ioStream.get()));
+    if (!stream) {
+        completionHandler(-1);
+        return;
+    }
+
     WriteAsyncData* asyncData = new WriteAsyncData { this, data.soupBuffer(), completionHandler };
     // FIXME: implement offset.
     g_output_stream_write_async(stream, asyncData->buffer->data, data.size(), G_PRIORITY_DEFAULT, nullptr,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to