From 235e3da90a4212d0c204afaef09db3408abfab82 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Mon, 18 Feb 2019 11:00:04 -0800 Subject: [PATCH] HDFS-14287. DataXceiverServer May Double-Close PeerServer. Contributed by BELUGA BEHR. --- .../server/datanode/DataXceiverServer.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataXceiverServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataXceiverServer.java index 8faae63e37..46cb21e8d3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataXceiverServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataXceiverServer.java @@ -244,12 +244,17 @@ public void run() { } // Close the server to stop reception of more requests. + lock.lock(); try { - peerServer.close(); - closed = true; + if (!closed) { + peerServer.close(); + closed = true; + } } catch (IOException ie) { LOG.warn("{}:DataXceiverServer: close exception", datanode.getDisplayName(), ie); + } finally { + lock.unlock(); } // if in restart prep stage, notify peers before closing them. @@ -270,11 +275,16 @@ void kill() { assert (datanode.shouldRun == false || datanode.shutdownForUpgrade) : "shoudRun should be set to false or restarting should be true" + " before killing"; + lock.lock(); try { - this.peerServer.close(); - this.closed = true; + if (!closed) { + peerServer.close(); + closed = true; + } } catch (IOException ie) { LOG.warn("{}:DataXceiverServer.kill()", datanode.getDisplayName(), ie); + } finally { + lock.unlock(); } }