7fc18b8
From f7abffec751e454d119df273dc6e49e5f7106078 Mon Sep 17 00:00:00 2001
7fc18b8
From: Sage Weil <sage@redhat.com>
7fc18b8
Date: Wed, 7 Dec 2016 18:25:55 -0600
7fc18b8
Subject: [PATCH] msg/simple/Pipe: avoid returning 0 on poll timeout
7fc18b8
7fc18b8
If poll times out it will return 0 (no data to read on socket).  In
7fc18b8
165e5abdbf6311974d4001e43982b83d06f9e0cc we changed tcp_read_wait from
7fc18b8
returning -1 to returning -errno, which means we return 0 instead of -1
7fc18b8
in this case.
7fc18b8
7fc18b8
This makes tcp_read() get into an infinite loop by repeatedly trying to
7fc18b8
read from the socket and getting EAGAIN.
7fc18b8
7fc18b8
Fix by explicitly checking for a 0 return from poll(2) and returning
7fc18b8
EAGAIN in that case.
7fc18b8
7fc18b8
Fixes: http://tracker.ceph.com/issues/18184
7fc18b8
Signed-off-by: Sage Weil <sage@redhat.com>
7fc18b8
(cherry picked from commit 6c3d015c6854a12cda40673848813d968ff6afae)
7fc18b8
---
7fc18b8
 src/msg/simple/Pipe.cc | 5 ++++-
7fc18b8
 1 file changed, 4 insertions(+), 1 deletion(-)
7fc18b8
7fc18b8
diff --git a/src/msg/simple/Pipe.cc b/src/msg/simple/Pipe.cc
7fc18b8
index 80b948d..cfb1986 100644
7fc18b8
--- a/src/msg/simple/Pipe.cc
7fc18b8
+++ b/src/msg/simple/Pipe.cc
7fc18b8
@@ -2500,8 +2500,11 @@ int Pipe::tcp_read_wait()
7fc18b8
   if (has_pending_data())
7fc18b8
     return 0;
7fc18b8
 
7fc18b8
-  if (poll(&pfd, 1, msgr->timeout) <= 0)
7fc18b8
+  int r = poll(&pfd, 1, msgr->timeout);
7fc18b8
+  if (r < 0)
7fc18b8
     return -errno;
7fc18b8
+  if (r == 0)
7fc18b8
+    return -EAGAIN;
7fc18b8
 
7fc18b8
   evmask = POLLERR | POLLHUP | POLLNVAL;
7fc18b8
 #if defined(__linux__)
7fc18b8
-- 
7fc18b8
2.7.4
7fc18b8