Add a IPC::SendSyncOption indicating we should not process incoming IPC while waiting...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Jan 2018 22:00:33 +0000 (22:00 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Jan 2018 22:00:33 +0000 (22:00 +0000)
commitfe43fa9e34e4921e272d4e6b14f1a8fe9b473851
treea8a13173109a5ab3184de1b1c69d51c1beb78842
parent961add2bc2744ff315cd78c81852ad56c163b4c1
Add a IPC::SendSyncOption indicating we should not process incoming IPC while waiting for the sync reply
https://bugs.webkit.org/show_bug.cgi?id=182021
<rdar://problem/21629943>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Add layout testing infrastructure for the new flag.

Test: fast/misc/testIncomingSyncIPCMessageWhileWaitingForSyncReply.html

* page/ChromeClient.h:
* testing/Internals.cpp:
(WebCore::Internals::testIncomingSyncIPCMessageWhileWaitingForSyncReply):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Add a new DoNotProcessIncomingMessagesWhenWaitingForSyncReply SendSyncOption that the caller can
set when calling sendSync(). This indicates that the sendSync() should return only when we receive
the response to our sync IPC message, and that we should not process ANY incoming IPC in the meantime.

This patch also starts using this flag in 3 places where we know processing incoming IPC is an issue
and is causing crashes.

* Platform/IPC/Connection.cpp:
(IPC::Connection::sendSyncMessage):
When DoNotProcessIncomingMessagesWhenWaitingForSyncReply SendSyncOption is set, make sure
we set the ShouldDispatchMessageWhenWaitingForSyncReply flag on the encoder. If we did not set this
flag then it could cause deadlocks when the destination process is also waiting on a synchronous
IPC from us. Normally, this flag already gets set for sync messages because sendSyncMessage() calls
sendMessage() with DispatchMessageEvenWhenWaitingForSyncReply SyncOption. However, sendMessage()
ignores the DispatchMessageEvenWhenWaitingForSyncReply flag if the
m_onlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage flag is set on the
connection. Note that this flag is set on the connection from the WebProcess to the UIProcess at
the moment, which is why we saw deadlocks on the previous iteration of this patch.

(IPC::Connection::waitForSyncReply):
If DoNotProcessIncomingMessagesWhenWaitingForSyncReply SendSyncOption is set, do not
process incoming IPC messages while waiting for our sync IPC reply.

* Platform/IPC/Connection.h:
Add new SendSyncOption.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::testIncomingSyncIPCMessageWhileWaitingForSyncReply):
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:
Testing infrastructure.

* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::loadResourceSynchronously):
Use new flag.

* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::testIncomingSyncIPCMessageWhileWaitingForSyncReply):
* WebProcess/WebCoreSupport/WebChromeClient.h:
Testing infrastructure.

* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::cookieRequestHeaderFieldValue):
Use new flag.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::syncIPCMessageWhileWaitingForSyncReplyForTesting):
Testing infrastructure.

(WebKit::WebProcess::ensureNetworkProcessConnection):
Use new flag.

* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:
Testing infrastructure.

LayoutTests:

Add layout test coverage for the new flag.

* fast/misc/testIncomingSyncIPCMessageWhileWaitingForSyncReply-expected.txt: Added.
* fast/misc/testIncomingSyncIPCMessageWhileWaitingForSyncReply.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227566 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/misc/testIncomingSyncIPCMessageWhileWaitingForSyncReply-expected.txt [new file with mode: 0644]
LayoutTests/fast/misc/testIncomingSyncIPCMessageWhileWaitingForSyncReply.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/ChromeClient.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/Platform/IPC/Connection.cpp
Source/WebKit/Platform/IPC/Connection.h
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/WebProcessProxy.messages.in
Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Source/WebKit/WebProcess/WebProcess.cpp
Source/WebKit/WebProcess/WebProcess.h
Source/WebKit/WebProcess/WebProcess.messages.in