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

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 150893002: Fix posix IPC channel hanging problem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reordered early exit, as requested Created 6 years, 10 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | ipc/ipc_channel_posix_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ipc/ipc_channel_posix.h" 5 #include "ipc/ipc_channel_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 13 matching lines...) Expand all
24 #include "base/file_util.h" 24 #include "base/file_util.h"
25 #include "base/files/file_path.h" 25 #include "base/files/file_path.h"
26 #include "base/location.h" 26 #include "base/location.h"
27 #include "base/logging.h" 27 #include "base/logging.h"
28 #include "base/memory/scoped_ptr.h" 28 #include "base/memory/scoped_ptr.h"
29 #include "base/memory/singleton.h" 29 #include "base/memory/singleton.h"
30 #include "base/posix/eintr_wrapper.h" 30 #include "base/posix/eintr_wrapper.h"
31 #include "base/posix/global_descriptors.h" 31 #include "base/posix/global_descriptors.h"
32 #include "base/process/process_handle.h" 32 #include "base/process/process_handle.h"
33 #include "base/rand_util.h" 33 #include "base/rand_util.h"
34 #include "base/run_loop.h"
34 #include "base/stl_util.h" 35 #include "base/stl_util.h"
35 #include "base/strings/string_util.h" 36 #include "base/strings/string_util.h"
36 #include "base/synchronization/lock.h" 37 #include "base/synchronization/lock.h"
37 #include "ipc/file_descriptor_set_posix.h" 38 #include "ipc/file_descriptor_set_posix.h"
38 #include "ipc/ipc_descriptors.h" 39 #include "ipc/ipc_descriptors.h"
39 #include "ipc/ipc_listener.h" 40 #include "ipc/ipc_listener.h"
40 #include "ipc/ipc_logging.h" 41 #include "ipc/ipc_logging.h"
41 #include "ipc/ipc_message_utils.h" 42 #include "ipc/ipc_message_utils.h"
42 #include "ipc/ipc_switches.h" 43 #include "ipc/ipc_switches.h"
43 #include "ipc/unix_domain_socket_util.h" 44 #include "ipc/unix_domain_socket_util.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 server_listen_pipe_ = local_pipe; 321 server_listen_pipe_ = local_pipe;
321 local_pipe = -1; 322 local_pipe = -1;
322 } 323 }
323 324
324 pipe_ = local_pipe; 325 pipe_ = local_pipe;
325 return true; 326 return true;
326 } 327 }
327 328
328 bool Channel::ChannelImpl::Connect() { 329 bool Channel::ChannelImpl::Connect() {
329 if (server_listen_pipe_ == -1 && pipe_ == -1) { 330 if (server_listen_pipe_ == -1 && pipe_ == -1) {
330 DLOG(INFO) << "Channel creation failed: " << pipe_name_; 331 DLOG(WARNING) << "Channel creation failed: " << pipe_name_;
331 return false; 332 return false;
332 } 333 }
333 334
334 bool did_connect = true; 335 bool did_connect = true;
335 if (server_listen_pipe_ != -1) { 336 if (server_listen_pipe_ != -1) {
336 // Watch the pipe for connections, and turn any connections into 337 // Watch the pipe for connections, and turn any connections into
337 // active sockets. 338 // active sockets.
338 base::MessageLoopForIO::current()->WatchFileDescriptor( 339 base::MessageLoopForIO::current()->WatchFileDescriptor(
339 server_listen_pipe_, 340 server_listen_pipe_,
340 true, 341 true,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 513
513 bool Channel::ChannelImpl::Send(Message* message) { 514 bool Channel::ChannelImpl::Send(Message* message) {
514 DVLOG(2) << "sending message @" << message << " on channel @" << this 515 DVLOG(2) << "sending message @" << message << " on channel @" << this
515 << " with type " << message->type() 516 << " with type " << message->type()
516 << " (" << output_queue_.size() << " in queue)"; 517 << " (" << output_queue_.size() << " in queue)";
517 518
518 #ifdef IPC_MESSAGE_LOG_ENABLED 519 #ifdef IPC_MESSAGE_LOG_ENABLED
519 Logging::GetInstance()->OnSendMessage(message, ""); 520 Logging::GetInstance()->OnSendMessage(message, "");
520 #endif // IPC_MESSAGE_LOG_ENABLED 521 #endif // IPC_MESSAGE_LOG_ENABLED
521 522
523 if (!waiting_connect_ && pipe_ == -1) {
524 delete message;
525 return false;
526 }
527
522 message->TraceMessageBegin(); 528 message->TraceMessageBegin();
523 output_queue_.push(message); 529 output_queue_.push(message);
524 if (!is_blocked_on_write_ && !waiting_connect_) { 530 if (!is_blocked_on_write_ && !waiting_connect_) {
525 return ProcessOutgoingMessages(); 531 if (!ProcessOutgoingMessages()) {
532 ClosePipeOnError();
533 return false;
534 }
526 } 535 }
527 536
528 return true; 537 return true;
529 } 538 }
530 539
531 int Channel::ChannelImpl::GetClientFileDescriptor() { 540 int Channel::ChannelImpl::GetClientFileDescriptor() {
532 base::AutoLock lock(client_pipe_lock_); 541 base::AutoLock lock(client_pipe_lock_);
533 return client_pipe_; 542 return client_pipe_;
534 } 543 }
535 544
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 bool Channel::ChannelImpl::AcceptConnection() { 709 bool Channel::ChannelImpl::AcceptConnection() {
701 base::MessageLoopForIO::current()->WatchFileDescriptor( 710 base::MessageLoopForIO::current()->WatchFileDescriptor(
702 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this); 711 pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this);
703 QueueHelloMessage(); 712 QueueHelloMessage();
704 713
705 if (mode_ & MODE_CLIENT_FLAG) { 714 if (mode_ & MODE_CLIENT_FLAG) {
706 // If we are a client we want to send a hello message out immediately. 715 // If we are a client we want to send a hello message out immediately.
707 // In server mode we will send a hello message when we receive one from a 716 // In server mode we will send a hello message when we receive one from a
708 // client. 717 // client.
709 waiting_connect_ = false; 718 waiting_connect_ = false;
710 return ProcessOutgoingMessages(); 719 if (!ProcessOutgoingMessages()) {
720 ClosePipeOnError();
721 return false;
722 }
723 return true;
711 } else if (mode_ & MODE_SERVER_FLAG) { 724 } else if (mode_ & MODE_SERVER_FLAG) {
712 waiting_connect_ = true; 725 waiting_connect_ = true;
713 return true; 726 return true;
714 } else { 727 } else {
715 NOTREACHED(); 728 NOTREACHED();
716 return false; 729 return false;
717 } 730 }
718 } 731 }
719 732
720 void Channel::ChannelImpl::ClosePipeOnError() { 733 void Channel::ChannelImpl::ClosePipeOnError() {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 1114
1102 1115
1103 #if defined(OS_LINUX) 1116 #if defined(OS_LINUX)
1104 // static 1117 // static
1105 void Channel::SetGlobalPid(int pid) { 1118 void Channel::SetGlobalPid(int pid) {
1106 ChannelImpl::SetGlobalPid(pid); 1119 ChannelImpl::SetGlobalPid(pid);
1107 } 1120 }
1108 #endif // OS_LINUX 1121 #endif // OS_LINUX
1109 1122
1110 } // namespace IPC 1123 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc_channel_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698