ceph/0002-msg-simple-Pipe-avoid-...

44 lines
1.3 KiB
Diff

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