Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1373)

Unified Diff: mojo/edk/test/multiprocess_test_helper.cc

Issue 2515043002: Mojo EDK: Fix race in named pipe creation for tests (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/test/multiprocess_test_helper.cc
diff --git a/mojo/edk/test/multiprocess_test_helper.cc b/mojo/edk/test/multiprocess_test_helper.cc
index 68336bd8a60de229d5f6cbf074f5f9ffbb3b1945..9aa9b0c6f7b9ec8c5f3face84c676a6f77993d2f 100644
--- a/mojo/edk/test/multiprocess_test_helper.cc
+++ b/mojo/edk/test/multiprocess_test_helper.cc
@@ -140,17 +140,26 @@ ScopedMessagePipeHandle MultiprocessTestHelper::StartChildWithExtraSwitch(
#error "Not supported yet."
#endif
+ // NOTE: In the case of named pipes, it's important that the server handle be
+ // created before the child process is launched; otherwise the server binding
+ // the pipe path can race with child's connection to the pipe.
+ ScopedPlatformHandle server_handle;
+ if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) {
+ server_handle = channel.PassServerHandle();
+ } else if (launch_type == LaunchType::NAMED_CHILD ||
+ launch_type == LaunchType::NAMED_PEER) {
+ server_handle = CreateServerHandle(named_pipe);
+ }
+
ScopedMessagePipeHandle pipe;
std::string child_token = mojo::edk::GenerateRandomToken();
if (launch_type == LaunchType::CHILD ||
launch_type == LaunchType::NAMED_CHILD) {
pipe = CreateParentMessagePipe(pipe_token, child_token);
- } else if (launch_type == LaunchType::PEER) {
- peer_token_ = mojo::edk::GenerateRandomToken();
- pipe = ConnectToPeerProcess(channel.PassServerHandle(), peer_token_);
- } else if (launch_type == LaunchType::NAMED_PEER) {
+ } else if (launch_type == LaunchType::PEER ||
+ launch_type == LaunchType::NAMED_PEER) {
peer_token_ = mojo::edk::GenerateRandomToken();
- pipe = ConnectToPeerProcess(CreateServerHandle(named_pipe), peer_token_);
+ pipe = ConnectToPeerProcess(std::move(server_handle), peer_token_);
}
test_child_ =
@@ -158,11 +167,10 @@ ScopedMessagePipeHandle MultiprocessTestHelper::StartChildWithExtraSwitch(
if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER)
channel.ChildProcessLaunched();
- if (launch_type == LaunchType::CHILD) {
- ChildProcessLaunched(test_child_.Handle(), channel.PassServerHandle(),
- child_token, process_error_callback_);
- } else if (launch_type == LaunchType::NAMED_CHILD) {
- ChildProcessLaunched(test_child_.Handle(), CreateServerHandle(named_pipe),
+ if (launch_type == LaunchType::CHILD ||
+ launch_type == LaunchType::NAMED_CHILD) {
+ DCHECK(server_handle.is_valid());
+ ChildProcessLaunched(test_child_.Handle(), std::move(server_handle),
child_token, process_error_callback_);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698