diff options
author | hubbe@chromium.org <hubbe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-02 20:53:06 +0000 |
---|---|---|
committer | hubbe@chromium.org <hubbe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-02 20:53:06 +0000 |
commit | 3a70c6d47b3fcf722951b71f85d46da970d6473f (patch) | |
tree | 453ac420409ba707e210a8bbceeeae28964d9b3a /ipc | |
parent | 02768b76b20034d7323fecfab05ecbaa1beeff7e (diff) | |
download | chromium_src-3a70c6d47b3fcf722951b71f85d46da970d6473f.zip chromium_src-3a70c6d47b3fcf722951b71f85d46da970d6473f.tar.gz chromium_src-3a70c6d47b3fcf722951b71f85d46da970d6473f.tar.bz2 |
There is a bug in the mac kernel, which can cause a file descriptor to be closed
when sent multiple times between processes. By delaying the close on the sender side by
a few second, we can eliminate this problem.
BUG=279443, 298276
Review URL: https://codereview.chromium.org/24365008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/file_descriptor_set_posix.cc | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/ipc/file_descriptor_set_posix.cc b/ipc/file_descriptor_set_posix.cc index 584efec..13356b7 100644 --- a/ipc/file_descriptor_set_posix.cc +++ b/ipc/file_descriptor_set_posix.cc @@ -8,9 +8,19 @@ #include <sys/stat.h> #include <unistd.h> +#include "base/bind.h" #include "base/logging.h" +#include "base/message_loop/message_loop.h" #include "base/posix/eintr_wrapper.h" +namespace { +// Used as callback. +static void CloseFD(int fd) { + if (HANDLE_EINTR(close(fd)) < 0) + PLOG(ERROR) << "close"; +} +} // namespace + FileDescriptorSet::FileDescriptorSet() : consumed_descriptor_highwater_(0) { } @@ -118,9 +128,26 @@ bool FileDescriptorSet::ContainsDirectoryDescriptor() const { void FileDescriptorSet::CommitAll() { for (std::vector<base::FileDescriptor>::iterator i = descriptors_.begin(); i != descriptors_.end(); ++i) { - if (i->auto_close) - if (HANDLE_EINTR(close(i->fd)) < 0) - PLOG(ERROR) << "close"; + if (i->auto_close) { +#if defined(OS_MACOSX) + // On mac, a sent file descriptor will sometimes get closed + // by a kernel garbage collector. By delaying the close by + // a few seconds, we can solve this once and for all. + // - but... + // - ONCE AND FOR ALL + // https://code.google.com/p/chromium/issues/detail?id=298276 + if (base::MessageLoop::current()) { + base::MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&CloseFD, i->fd), + base::TimeDelta::FromSeconds(5)); + } else { + CloseFD(i->fd); + } +#else // OS_MACOSX + CloseFD(i->fd); +#endif // OS_MACOSX + } } descriptors_.clear(); consumed_descriptor_highwater_ = 0; |