Skip to content

Commit

Permalink
[JENKINS-23248] Making the close method more robust
Browse files Browse the repository at this point in the history
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 6c7d4d1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/hudson/remoting/SocketChannelStream.java
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6c7d4d1

Please sign in to comment.