Index: src/java/org/apache/hadoop/ipc/Client.java =================================================================== --- src/java/org/apache/hadoop/ipc/Client.java (revision 984461) +++ src/java/org/apache/hadoop/ipc/Client.java (working copy) @@ -796,34 +796,53 @@ connections.remove(remoteId); } } - - // close the streams and therefore the socket - IOUtils.closeStream(out); - IOUtils.closeStream(in); - disposeSasl(); - - // clean up all calls - if (closeException == null) { - if (!calls.isEmpty()) { - LOG.warn( - "A connection is closed for no cause and calls are not empty"); - - // clean up calls anyway - closeException = new IOException("Unexpected closed connection"); + + /* + * The Connection object may have been partially built. + * Catch runtime exceptions resulting from the partially + * built object + */ + try { + if (socket==null) throw new IOException("Connection did not acquire a socket"); + + // close the streams and therefore the socket + if (out!=null) IOUtils.closeStream(out); + if (in!=null) IOUtils.closeStream(in); + disposeSasl(); + + // clean up all calls + if (closeException == null) { + if (!calls.isEmpty()) { + LOG.warn( + "A connection is closed for no cause and calls are not empty"); + + // clean up calls anyway + closeException = new IOException("Unexpected closed connection"); + cleanupCalls(); + } + } else { + // log the info + if (LOG.isDebugEnabled()) { + LOG.debug("closing ipc connection to " + server + ": " + + closeException.getMessage(),closeException); + } + + // cleanup calls cleanupCalls(); } - } else { - // log the info - if (LOG.isDebugEnabled()) { - LOG.debug("closing ipc connection to " + server + ": " + - closeException.getMessage(),closeException); - } - - // cleanup calls - cleanupCalls(); + if (LOG.isDebugEnabled()) + LOG.debug(getName() + ": closed"); + } catch (IOException e) { + // Capture the current exception + if (LOG.isDebugEnabled()) LOG.debug(e.getLocalizedMessage(), e); + if (closeException==null) closeException = e; + else closeException = new IOException (e.getLocalizedMessage(), closeException); + } catch (Exception e) { + // Capture the current exception + if (LOG.isDebugEnabled()) LOG.debug(e.getLocalizedMessage(), e); + if (closeException==null) closeException = new IOException(e); + else closeException = new IOException (e.getLocalizedMessage(), closeException); } - if (LOG.isDebugEnabled()) - LOG.debug(getName() + ": closed"); } /* Cleanup all calls and mark them as done */