From f13eaf4ca8116fed7c984f0d4edaf53ea8cca2f9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 20 Sep 2012 10:14:24 -0700 Subject: [PATCH] msg/Accepter: fix race in accepter shutdown We want to avoid a race like: - entry() starts, populates pfd with listen_sd, gets past !done check - stop() does shutdown + close on listen_sd - someone else opens a new fd - entry() thread calls poll(2) on wrong sd - stop() calls join, waits forever for entry thread Signed-off-by: Sage Weil --- src/msg/Accepter.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/msg/Accepter.cc b/src/msg/Accepter.cc index 03e2d65211e4c..28a475079c695 100644 --- a/src/msg/Accepter.cc +++ b/src/msg/Accepter.cc @@ -247,10 +247,16 @@ void Accepter::stop() ldout(msgr->cct,10) << "stop accepter" << dendl; if (listen_sd >= 0) { ::shutdown(listen_sd, SHUT_RDWR); + } + + // wait for thread to stop before closing the socket, to avoid + // racing against fd re-use. + join(); + + if (listen_sd >= 0) { ::close(listen_sd); listen_sd = -1; } - join(); done = false; } -- 2.39.5