You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ma...@apache.org on 2012/04/25 00:04:14 UTC

svn commit: r1330041 - in /hadoop/common/branches/branch-1: ./ CHANGES.txt src/core/org/apache/hadoop/ipc/Client.java src/mapred/ src/test/org/apache/hadoop/ipc/TestIPC.java

Author: mattf
Date: Tue Apr 24 22:04:14 2012
New Revision: 1330041

URL: http://svn.apache.org/viewvc?rev=1330041&view=rev
Log:
HADOOP-8294. IPC Connection becomes unusable even if server address was temporarilly unresolvable. Backport of HADOOP-7428. Contributed by Kihwal Lee.

Modified:
    hadoop/common/branches/branch-1/   (props changed)
    hadoop/common/branches/branch-1/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/branch-1/src/core/org/apache/hadoop/ipc/Client.java
    hadoop/common/branches/branch-1/src/mapred/   (props changed)
    hadoop/common/branches/branch-1/src/test/org/apache/hadoop/ipc/TestIPC.java

Propchange: hadoop/common/branches/branch-1/
------------------------------------------------------------------------------
  Merged /hadoop/common/branches/branch-1.0:r1330040

Modified: hadoop/common/branches/branch-1/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/CHANGES.txt?rev=1330041&r1=1330040&r2=1330041&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1/CHANGES.txt Tue Apr 24 22:04:14 2012
@@ -271,6 +271,9 @@ Release 1.0.3 - unreleased
     HDFS-119. Fix a bug in logSync(), which causes NameNode block
     forever. (shv)
 
+    HADOOP-8294. IPC Connection becomes unusable even if server address was temporarilly
+    unresolvable. Backport of HADOOP-7428. (Kihwal Lee via mattf)
+
 Release 1.0.2 - 2012.03.24
 
   NEW FEATURES

Propchange: hadoop/common/branches/branch-1/CHANGES.txt
------------------------------------------------------------------------------
  Merged /hadoop/common/branches/branch-1.0/CHANGES.txt:r1330040

Modified: hadoop/common/branches/branch-1/src/core/org/apache/hadoop/ipc/Client.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/ipc/Client.java?rev=1330041&r1=1330040&r2=1330041&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/core/org/apache/hadoop/ipc/Client.java (original)
+++ hadoop/common/branches/branch-1/src/core/org/apache/hadoop/ipc/Client.java Tue Apr 24 22:04:14 2012
@@ -612,8 +612,12 @@ public class Client {
           start();
           return;
         }
-      } catch (IOException e) {
-        markClosed(e);
+      } catch (Throwable t) {
+        if (t instanceof IOException) {
+          markClosed((IOException)t);
+        } else {
+          markClosed(new IOException("Couldn't set up IO streams", t));
+        }
         close();
       }
     }

Propchange: hadoop/common/branches/branch-1/src/mapred/
------------------------------------------------------------------------------
  Merged /hadoop/common/branches/branch-1.0/src/mapred:r1330040

Modified: hadoop/common/branches/branch-1/src/test/org/apache/hadoop/ipc/TestIPC.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/test/org/apache/hadoop/ipc/TestIPC.java?rev=1330041&r1=1330040&r2=1330041&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/test/org/apache/hadoop/ipc/TestIPC.java (original)
+++ hadoop/common/branches/branch-1/src/test/org/apache/hadoop/ipc/TestIPC.java Tue Apr 24 22:04:14 2012
@@ -29,12 +29,20 @@ import java.util.Random;
 import java.io.DataInput;
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.Socket;
 import java.net.SocketTimeoutException;
 
+import javax.net.SocketFactory;
+
 import junit.framework.TestCase;
 
 import org.apache.hadoop.conf.Configuration;
 
+import static org.mockito.Mockito.*;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
 /** Unit tests for IPC. */
 public class TestIPC extends TestCase {
   public static final Log LOG =
@@ -235,6 +243,52 @@ public class TestIPC extends TestCase {
     }
   }
 
+  /**
+  * Test that, if a RuntimeException is thrown after creating a socket
+  * but before successfully connecting to the IPC server, that the
+  * failure is handled properly. This is a regression test for
+  * HADOOP-7428 (HADOOP-8294).
+  */
+  public void testRTEDuringConnectionSetup() throws Exception {
+    // Set up a socket factory which returns sockets which
+    // throw an RTE when setSoTimeout is called.
+    SocketFactory spyFactory = spy(NetUtils.getDefaultSocketFactory(conf));
+    Mockito.doAnswer(new Answer<Socket>() {
+      @Override
+      public Socket answer(InvocationOnMock invocation) throws Throwable {
+        Socket s = spy((Socket)invocation.callRealMethod());
+        doThrow(new RuntimeException("Injected fault")).when(s)
+          .setSoTimeout(anyInt());
+        return s;
+      }
+    }).when(spyFactory).createSocket();
+ 
+    Server server = new TestServer(1, true);
+    server.start();
+    try {
+      // Call should fail due to injected exception.
+      InetSocketAddress address = NetUtils.getConnectAddress(server);
+      Client client = new Client(LongWritable.class, conf, spyFactory);
+      try {
+        client.call(new LongWritable(RANDOM.nextLong()),
+                address, null, null, 0, conf);
+        fail("Expected an exception to have been thrown");
+      } catch (Exception e) {
+        LOG.info("caught expected exception", e);
+        assertTrue(StringUtils.stringifyException(e).contains(
+            "Injected fault"));
+      }
+      // Resetting to the normal socket behavior should succeed
+      // (i.e. it should not have cached a half-constructed connection)
+  
+      Mockito.reset(spyFactory);
+      client.call(new LongWritable(RANDOM.nextLong()),
+          address, null, null, 0, conf);
+    } finally {
+      server.stop();
+    }
+  }
+
   public void testIpcTimeout() throws Exception {
     // start server
     Server server = new TestServer(1, true);