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 Jan 3, 2019
1 parent 9ed5021 commit 5e29c0f
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
Original file line number Diff line number Diff line change
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 5e29c0f

Please sign in to comment.