Cancel read input stream source of WebSocket when migrating to new page
authorpraveen.ks <praveen.ks@samsung.com>
Thu, 2 May 2013 13:34:43 +0000 (22:34 +0900)
committerGerrit Code Review <gerrit2@kim11>
Wed, 8 May 2013 05:21:30 +0000 (14:21 +0900)
[Title] Fix for WebProcess hang when WebSocket is open while migrating to new page
[Issue#] WEB-2823 and TD-9578
[Problem] WebProcess hangs when we load a new page while existing page had WebSocket open
[Cause] When closing i/o stream the input stream socket gsource is not cancelled
[Solution] Pass a cancellable object while reading input stream and call cancel on the cancellable object before closing i/o stream
[Developer] Praveen (praveen.ks@samsung.com)

Change-Id: I93267871a83f58251940d02e3aca6e854b367ddf

Source/WTF/wtf/Platform.h [changed mode: 0644->0755]
Source/WebCore/platform/network/soup/SocketStreamHandle.h [changed mode: 0644->0755]
Source/WebCore/platform/network/soup/tizen/SocketStreamHandleSoupTizen.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 8e72f9e..e5ccf36
@@ -811,6 +811,8 @@ com) : Patch to do not adjust cover rect as fixed pixel size*/
 
 #define ENABLE_TIZEN_FULLSCREEN_API 1 /* Jongseok Yang(js45.yang@samsung.com) : Implement the smart function for fullscreen API */
 
+#define ENABLE_TIZEN_WEBSOCKET_ADD_CANCELLABLE 1 /* Praveen (praveen.ks@samsung.com) : Add cancellable to input stream and cancel the cancellable when we close the platform */
+
 #if ENABLE(WORKERS)
 #define ENABLE_TIZEN_WORKERS 1 /* Jihye Kang(jye.kang@samsung.com) : Use allowUniversalAccessFromFileURLs setting for workers */
 #endif
old mode 100644 (file)
new mode 100755 (executable)
index c2449c7..b8480b4
@@ -64,7 +64,9 @@ namespace WebCore {
         GRefPtr<GSource> m_writeReadySource;
         char* m_readBuffer;
         void* m_id;
-
+#if ENABLE(TIZEN_WEBSOCKET_ADD_CANCELLABLE)
+        GRefPtr<GCancellable> m_cancellable;
+#endif
         SocketStreamHandle(const KURL&, SocketStreamHandleClient*);
 
         // No authentication for streams per se, but proxy may ask for credentials.
old mode 100644 (file)
new mode 100755 (executable)
index 3501134..06bc6cc
@@ -121,8 +121,14 @@ void SocketStreamHandle::connected(GSocketConnection* socketConnection, GError*
     m_inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_socketConnection.get()));
 
     m_readBuffer = new char[READ_BUFFER_SIZE];
+#if ENABLE(TIZEN_WEBSOCKET_ADD_CANCELLABLE)
+    m_cancellable = g_cancellable_new();
+    g_input_stream_read_async(m_inputStream.get(), m_readBuffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, m_cancellable.get(),
+        reinterpret_cast<GAsyncReadyCallback>(readReadyCallback), m_id);
+#else
     g_input_stream_read_async(m_inputStream.get(), m_readBuffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, 0,
         reinterpret_cast<GAsyncReadyCallback>(readReadyCallback), m_id);
+#endif
 
     m_state = Open;
     m_client->didOpenSocketStream(this);
@@ -144,8 +150,13 @@ void SocketStreamHandle::readBytes(signed long bytesRead, GError* error)
     RefPtr<SocketStreamHandle> protect(this);
     m_client->didReceiveSocketStreamData(this, m_readBuffer, bytesRead);
     if (m_inputStream) // The client may have closed the connection.
+#if ENABLE(TIZEN_WEBSOCKET_ADD_CANCELLABLE)
+        g_input_stream_read_async(m_inputStream.get(), m_readBuffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, m_cancellable.get(),
+            reinterpret_cast<GAsyncReadyCallback>(readReadyCallback), m_id);
+#else
         g_input_stream_read_async(m_inputStream.get(), m_readBuffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, 0,
             reinterpret_cast<GAsyncReadyCallback>(readReadyCallback), m_id);
+#endif
 }
 
 void SocketStreamHandle::writeReady()
@@ -186,6 +197,9 @@ void SocketStreamHandle::platformClose()
     stopWaitingForSocketWritability();
 
     if (m_socketConnection) {
+#if ENABLE(TIZEN_WEBSOCKET_ADD_CANCELLABLE)
+        g_cancellable_cancel(m_cancellable.get());
+#endif
         GOwnPtr<GError> error;
         g_io_stream_close(G_IO_STREAM(m_socketConnection.get()), 0, &error.outPtr());
         if (error)
@@ -196,6 +210,9 @@ void SocketStreamHandle::platformClose()
     m_outputStream = 0;
     m_inputStream = 0;
     delete m_readBuffer;
+#if ENABLE(TIZEN_WEBSOCKET_ADD_CANCELLABLE)
+    m_cancellable = 0;
+#endif
 
     m_client->didCloseSocketStream(this);
 }