File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed
core/src/main/java/io/undertow/server/protocol/framed Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments