Skip to content

Commit 2bb93ae

Browse files
committed
[UNDERTOW-2574] At AbstractFramedChannel, also cover for the case where framedDataRemaining is zero and the last frame has been received, plus, make sure we are closing the buffer even if readData is null
Signed-off-by: Flavia Rainone <[email protected]>
1 parent 35f4863 commit 2bb93ae

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

core/src/main/java/io/undertow/server/protocol/framed/AbstractFramedChannel.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ public synchronized R receive() throws IOException {
430430
readData = null;
431431
}
432432
if(frameDataRemaining == 0) {
433+
if (isLastFrameReceived()) {
434+
forceFree = true;
435+
}
433436
receiver = null;
434437
}
435438
return null;
@@ -503,16 +506,21 @@ public synchronized R receive() throws IOException {
503506
}finally {
504507
//if the receive caused the channel to break the close listener may be have been called
505508
//which will make readData null
506-
if (readData != null) {
507-
if (!pooled.getBuffer().hasRemaining() || forceFree) {
508-
if(pooled.getBuffer().capacity() < 1024 || forceFree) {
509-
//if there is less than 1k left we don't allow it to be re-aquired
510-
readData = null;
509+
if (readData != null || pooled != null) {
510+
if (pooled.isOpen()) {
511+
try {
512+
if (forceFree || !pooled.getBuffer().hasRemaining()) {
513+
if (forceFree || pooled.getBuffer().capacity() < 1024) {
514+
//if there is less than 1k left we don't allow it to be re-aquired
515+
readData = null;
516+
}
517+
//even though this is freed we may un-free it if we get a new packet
518+
//this prevents many small reads resulting in a large number of allocated buffers
519+
pooled.close();
520+
}
521+
} catch (IllegalStateException illegalStateException) {
522+
// ignore, it can happen if we are racing with a close that has closed the pooled
511523
}
512-
//even though this is freed we may un-free it if we get a new packet
513-
//this prevents many small reads resulting in a large number of allocated buffers
514-
pooled.close();
515-
516524
}
517525
}
518526
if(requiresReinvoke) {

0 commit comments

Comments
 (0)