Skip to content

Commit

Permalink
[cherry-pick](SSL) Fix ssl connection close 2.1 (#38587) (#38677)
Browse files Browse the repository at this point in the history
## Proposed changes

Issue Number: close #38590 

If SSL connection closed, a specified packet will sent to indicate the
closing of connection. The SSL engine will be shut down and output an
empty unwrapped result.

Therefore, handle this case correctly to avoid buffer overflow by
breaking the reading flow and do the cleanup stuff initiatively.
  • Loading branch information
TangSiyang2001 authored Aug 1, 2024
1 parent 9d23ccf commit cafcf7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public ByteBuffer fetchOnePacket() throws IOException {
// before read, set limit to make read only one packet
result.limit(result.position() + packetLen);
readLen = readAll(result, false);
if (isSslMode && remainingBuffer.position() == 0) {
if (isSslMode && remainingBuffer.position() == 0 && result.hasRemaining()) {
byte[] header = result.array();
int packetId = header[3] & 0xFF;
if (packetId != sequenceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ public void processOnce() throws IOException {
LOG.warn("Null packet received from network. remote: {}", channel.getRemoteHostPortString());
throw new IOException("Error happened when receiving packet.");
}
if (!packetBuf.hasRemaining()) {
LOG.info("No more data to be read. Close connection. remote={}", channel.getRemoteHostPortString());
ctx.setKilled();
return;
}
} catch (AsynchronousCloseException e) {
// when this happened, timeout checker close this channel
// killed flag in ctx has been already set, just return
Expand Down

0 comments on commit cafcf7a

Please sign in to comment.