Skip to content
Permalink
Browse files
[FIXED JENKINS-23248] Seeing strange "Transport endpoint is not conne…
…cted" exception

s.shutdownInput() fails with the following exception, even though s.isInputShutdown() is reporting false:

java.net.SocketException: Transport endpoint is not connected
	at sun.nio.ch.SocketChannelImpl.shutdown(Native Method)
	at sun.nio.ch.SocketChannelImpl.shutdownInput(SocketChannelImpl.java:667)
	at sun.nio.ch.SocketAdaptor.shutdownInput(SocketAdaptor.java:378)
	at hudson.remoting.SocketChannelStream$1.close(SocketChannelStream.java:39)
	at sun.nio.ch.ChannelInputStream.close(ChannelInputStream.java:113)
	at javax.crypto.CipherInputStream.close(CipherInputStream.java:296)
	at java.io.BufferedInputStream.close(BufferedInputStream.java:468)
	at hudson.remoting.FlightRecorderInputStream.close(FlightRecorderInputStream.java:112)
	at hudson.remoting.ChunkedInputStream.close(ChunkedInputStream.java:102)
	at hudson.remoting.ChunkedCommandTransport.closeRead(ChunkedCommandTransport.java:50)
	at hudson.remoting.Channel.terminate(Channel.java:795)
	at hudson.remoting.Channel$CloseCommand.execute(Channel.java:951)
	at hudson.remoting.Channel$2.handle(Channel.java:475)
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:60)

This bug report may be related: http://bugs.java.com/view_bug.do?bug_id=4516760
If we fail to call s.close(), a socket will leak, so swallowing this exception and have the code execute "s.close()"
  • Loading branch information
kohsuke committed Jul 29, 2014
1 parent 6c7d4d1 commit c90fc463923cc7f4a8907a0b352204f3d561cc55
Showing with 13 additions and 2 deletions.
  1. +13 −2 src/main/java/hudson/remoting/SocketChannelStream.java
@@ -9,6 +9,7 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
@@ -36,7 +37,11 @@ public int read(ByteBuffer dst) throws IOException {

public void close() throws IOException {
if (!s.isInputShutdown()) {
s.shutdownInput();
try {
s.shutdownInput();
} catch (IOException e) {
LOGGER.log(Level.FINE, "Failed to shutdownInput", e);
}
}
if (s.isOutputShutdown()) {
ch.close();
@@ -67,7 +72,11 @@ public int write(ByteBuffer src) throws IOException {

public void close() throws IOException {
if (!s.isOutputShutdown()) {
s.shutdownOutput();
try {
s.shutdownOutput();
} catch (IOException e) {
LOGGER.log(Level.FINE, "Failed to shutdownOutput", e);
}
}
if (s.isInputShutdown()) {
ch.close();
@@ -80,4 +89,6 @@ public boolean isOpen() {
}
});
}

private static final Logger LOGGER = Logger.getLogger(SocketChannelStream.class.getName());
}

0 comments on commit c90fc46

Please sign in to comment.