Parcourir la source

HDFS-723. Fix deadlock in DFSClient#DFSOutputStream. Contributed by Hairong Kuang.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@829880 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang il y a 15 ans
Parent
commit
a189d531e8
2 fichiers modifiés avec 13 ajouts et 4 suppressions
  1. 2 0
      CHANGES.txt
  2. 11 4
      src/java/org/apache/hadoop/hdfs/DFSClient.java

+ 2 - 0
CHANGES.txt

@@ -453,6 +453,8 @@ Release 0.21.0 - Unreleased
     HDFS-725. Support the build error fix for HADOOP-6327.  (Sanjay Radia via
     szetszwo)
 
+    HDFS-723. Fix deadlock in DFSClient#DFSOutputStream. (hairong)
+
 Release 0.20.2 - Unreleased
 
   IMPROVEMENTS

+ 11 - 4
src/java/org/apache/hadoop/hdfs/DFSClient.java

@@ -1184,10 +1184,17 @@ public class DFSClient implements FSConstants, java.io.Closeable {
       }
     }
 
-    synchronized void close() {
-      while (!pendingCreates.isEmpty()) {
-        String src = pendingCreates.firstKey();
-        OutputStream out = pendingCreates.remove(src);
+    void close() {
+      while (true) {
+        String src;
+        OutputStream out;
+        synchronized (this) {
+          if (pendingCreates.isEmpty()) {
+            return;
+          }
+          src = pendingCreates.firstKey();
+          out = pendingCreates.remove(src);
+        }
         if (out != null) {
           try {
             out.close();