HADOOP-6724. IPC doesn't properly handle IOEs thrown by socket factory. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@939018 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas White 2010-04-28 17:34:55 +00:00
parent f1fee1804a
commit cd85fc46dc
3 changed files with 30 additions and 4 deletions

View File

@ -373,6 +373,9 @@ Trunk (unreleased changes)
HADOOP-6719. Insert all missing methods in FilterFs.
(Rodrigo Schmidt via dhruba)
HADOOP-6724. IPC doesn't properly handle IOEs thrown by socket factory.
(Todd Lipcon via tomwhite)
Release 0.21.0 - Unreleased
INCOMPATIBLE CHANGES

View File

@ -494,10 +494,12 @@ public Boolean run() throws IOException {
private void handleConnectionFailure(
int curRetries, int maxRetries, IOException ioe) throws IOException {
// close the current connection
try {
socket.close();
} catch (IOException e) {
LOG.warn("Not able to close a socket", e);
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
LOG.warn("Not able to close a socket", e);
}
}
// set socket to null so that the next call to setupIOstreams
// can start the process of connect all over again.

View File

@ -29,8 +29,10 @@
import java.io.DataInput;
import java.io.IOException;
import java.net.InetSocketAddress;
import javax.net.SocketFactory;
import junit.framework.TestCase;
import static org.mockito.Mockito.*;
import org.apache.hadoop.conf.Configuration;
@ -267,6 +269,25 @@ public void testErrorClient() throws Exception {
}
}
/**
* Test that, if the socket factory throws an IOE, it properly propagates
* to the client.
*/
public void testSocketFactoryException() throws Exception {
SocketFactory mockFactory = mock(SocketFactory.class);
doThrow(new IOException("Injected fault")).when(mockFactory).createSocket();
Client client = new Client(LongWritable.class, conf, mockFactory);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10);
try {
client.call(new LongWritable(RANDOM.nextLong()),
address, null, null);
fail("Expected an exception to have been thrown");
} catch (IOException e) {
assertTrue(e.getMessage().contains("Injected fault"));
}
}
public static void main(String[] args) throws Exception {