Skip to content

Commit

Permalink
Do not close socket if it is already closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer authored and oscarguindzberg committed Dec 20, 2018
1 parent 05c6432 commit f76a9da
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/src/main/java/org/bitcoinj/net/BlockingClient.java
Expand Up @@ -145,11 +145,14 @@ public void closeConnection() {
@Override
public synchronized void writeBytes(byte[] message) throws IOException {
try {
OutputStream stream = socket.getOutputStream();
stream.write(message);
stream.flush();
if(!socket.isClosed()) {
OutputStream stream = socket.getOutputStream();
stream.write(message);
stream.flush();
}
} catch (IOException e) {
log.error("Error writing message to connection, closing connection", e);
if(!(e instanceof SocketException && e.toString().equals("Socket is closed")))
log.error("Error writing message to connection, closing connection", e);
closeConnection();
throw e;
}
Expand Down

0 comments on commit f76a9da

Please sign in to comment.