Skip to content
Permalink
Browse files
[JENKINS-23248] Making the close method more robust
Unlike the usual close() method, shutdownInput/Output throws an exception for the 2nd invocation.
It's better to silently do nothing instead of dying with IOException.
  • Loading branch information
kohsuke committed Jul 29, 2014
1 parent fc5cf1a commit 6c7d4d110362106cf897fef6485b80dbd3755d4c
Showing with 7 additions and 2 deletions.
  1. +7 −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.Logger;

/**
* Wraps {@link SocketChannel} into {@link InputStream}/{@link OutputStream} in a way
@@ -34,7 +35,9 @@ public int read(ByteBuffer dst) throws IOException {
}

public void close() throws IOException {
s.shutdownInput();
if (!s.isInputShutdown()) {
s.shutdownInput();
}
if (s.isOutputShutdown()) {
ch.close();
s.close();
@@ -63,7 +66,9 @@ public int write(ByteBuffer src) throws IOException {
}

public void close() throws IOException {
s.shutdownOutput();
if (!s.isOutputShutdown()) {
s.shutdownOutput();
}
if (s.isInputShutdown()) {
ch.close();
s.close();

0 comments on commit 6c7d4d1

Please sign in to comment.