javaee / grizzly

Writing scalable server applications in the Java™ programming language has always been difficult. Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users. The Grizzly NIO framework has been designed to help developers to take advantage of the Java™ NIO API.
https://javaee.github.io/grizzly/
Other
222 stars 60 forks source link

LifecycleListener not notified about all causes of flush #1894

Closed glassfishrobot closed 7 years ago

glassfishrobot commented 7 years ago

The fix for #1839 do not invoke lifecycle listeners in all code paths where the Http headers might be actually committed.

In Glassfish I observe OutputBuffer.write(String, int,int) invoking flushBinaryBuffers(false) that in turn commits underlying HttpHeader. Glassfish also has lifecycle listener org.apache.catalina.connector.OutputBuffer$SessionCookieChecker that wants to put in Set-Cookie header right before sending the header out. However, it is not invoked along this codepath, only later when the header is already committed.

The behaviour is also described in Payara issue 1447

Environment

All

Affected Versions

[2.3.26]

glassfishrobot commented 7 years ago

Reported by pdudits

glassfishrobot commented 7 years ago

pdudits said: My humble attempt at fix would be to invoke doCommit in flushBinaryBuffers:

diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java b/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java
index e6eda42..dc501d8 100644
--- a/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java
+++ b/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java
@@ -1043,6 +1043,7 @@ public class OutputBuffer {
         }

         if (bufferToFlush != null) {
+            doCommit();
             flushBuffer(bufferToFlush, isLast, null);

             return true;
glassfishrobot commented 7 years ago

@rlubke said: Changes applied:

2.3.x: 35b3977671c154ab81f2039bde25f69e38384f04 master: dbfe68e591ccec62853bfc2ba7e924b454546f93

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA GRIZZLY-1894

glassfishrobot commented 7 years ago

Marked as fixed on Tuesday, March 14th 2017, 12:19:27 pm