Skip to content

Commit

Permalink
Fix bytebuffer clearing issue on write failure (#59)
Browse files Browse the repository at this point in the history
* Maybe fixes bytebuffer clearing issue when write fails

* Clear buffer on teardown

* Clear preAllocatedRXBuffer on teardown
  • Loading branch information
StrongestNumber9 authored Oct 16, 2023
1 parent d6a0944 commit e5e1555
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/teragrep/rlp_01/RelpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public void tearDown() {
; // don't care
}
this.state = RelpConnectionState.CLOSED;
this.preAllocatedTXBuffer.clear();
this.preAllocatedRXBuffer.clear();
}

/**
Expand Down Expand Up @@ -293,7 +295,10 @@ private void sendRelpRequestAsync(RelpFrameTX relpRequest) throws IOException, T
relpRequest.write(byteBuffer);

byteBuffer.flip();
relpClientSocket.write(byteBuffer);
byteBuffer.clear();
try {
relpClientSocket.write(byteBuffer);
} finally {
byteBuffer.clear();
}
}
}

0 comments on commit e5e1555

Please sign in to comment.