You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/08/10 00:05:39 UTC

mesos git commit: Fixed a use-after-close bug in PollSocketImpl.

Repository: mesos
Updated Branches:
  refs/heads/master f6a0e72c5 -> 42af83373


Fixed a use-after-close bug in PollSocketImpl.

Currently, the poll socket implementation doesn't keep
the socket alive after `PollSocketImpl.send(data, length)`
passes execution off to a continuation and so it may send
on a stale file descriptor!

Review: https://reviews.apache.org/r/50936/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/42af8337
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/42af8337
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/42af8337

Branch: refs/heads/master
Commit: 42af833732cb06597683220d0b37930a190e9842
Parents: f6a0e72
Author: Greg Mann <gr...@mesosphere.io>
Authored: Tue Aug 9 17:04:27 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Aug 9 17:04:27 2016 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/poll_socket.cpp | 39 +++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/42af8337/3rdparty/libprocess/src/poll_socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/poll_socket.cpp b/3rdparty/libprocess/src/poll_socket.cpp
index d14dd1a..a45cc20 100644
--- a/3rdparty/libprocess/src/poll_socket.cpp
+++ b/3rdparty/libprocess/src/poll_socket.cpp
@@ -162,12 +162,12 @@ Future<size_t> PollSocketImpl::recv(char* data, size_t size)
 
 namespace internal {
 
-Future<size_t> socket_send_data(int s, const char* data, size_t size)
+Future<size_t> socket_send_data(Socket socket, const char* data, size_t size)
 {
   CHECK(size > 0);
 
   while (true) {
-    ssize_t length = send(s, data, size, MSG_NOSIGNAL);
+    ssize_t length = send(socket.get(), data, size, MSG_NOSIGNAL);
 
 #ifdef __WINDOWS__
     int error = WSAGetLastError();
@@ -180,8 +180,8 @@ Future<size_t> socket_send_data(int s, const char* data, size_t size)
       continue;
     } else if (length < 0 && net::is_retryable_error(error)) {
       // Might block, try again later.
-      return io::poll(s, io::WRITE)
-        .then(lambda::bind(&internal::socket_send_data, s, data, size));
+      return io::poll(socket.get(), io::WRITE)
+        .then(lambda::bind(&internal::socket_send_data, socket, data, size));
     } else if (length <= 0) {
       // Socket error or closed.
       if (length < 0) {
@@ -204,12 +204,17 @@ Future<size_t> socket_send_data(int s, const char* data, size_t size)
 }
 
 
-Future<size_t> socket_send_file(int s, int fd, off_t offset, size_t size)
+Future<size_t> socket_send_file(
+    Socket socket,
+    int fd,
+    off_t offset,
+    size_t size)
 {
   CHECK(size > 0);
 
   while (true) {
-    Try<ssize_t, SocketError> length = os::sendfile(s, fd, offset, size);
+    Try<ssize_t, SocketError> length =
+      os::sendfile(socket.get(), fd, offset, size);
 
     if (length.isSome()) {
       CHECK(length.get() >= 0);
@@ -225,8 +230,13 @@ Future<size_t> socket_send_file(int s, int fd, off_t offset, size_t size)
       continue;
     } else if (net::is_retryable_error(length.error().code)) {
       // Might block, try again later.
-      return io::poll(s, io::WRITE)
-        .then(lambda::bind(&internal::socket_send_file, s, fd, offset, size));
+      return io::poll(socket.get(), io::WRITE)
+        .then(lambda::bind(
+            &internal::socket_send_file,
+            socket,
+            fd,
+            offset,
+            size));
     } else {
       // Socket error or closed.
       VLOG(1) << length.error().message;
@@ -241,14 +251,23 @@ Future<size_t> socket_send_file(int s, int fd, off_t offset, size_t size)
 Future<size_t> PollSocketImpl::send(const char* data, size_t size)
 {
   return io::poll(get(), io::WRITE)
-    .then(lambda::bind(&internal::socket_send_data, get(), data, size));
+    .then(lambda::bind(
+        &internal::socket_send_data,
+        socket(),
+        data,
+        size));
 }
 
 
 Future<size_t> PollSocketImpl::sendfile(int fd, off_t offset, size_t size)
 {
   return io::poll(get(), io::WRITE)
-    .then(lambda::bind(&internal::socket_send_file, get(), fd, offset, size));
+    .then(lambda::bind(
+        &internal::socket_send_file,
+        socket(),
+        fd,
+        offset,
+        size));
 }
 
 } // namespace network {