You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2024/02/16 05:14:26 UTC

[Bug 68634] New: Forwards using custom response classes do not wait for session replication

https://bz.apache.org/bugzilla/show_bug.cgi?id=68634

            Bug ID: 68634
           Summary: Forwards using custom response classes do not wait for
                    session replication
           Product: Tomcat 9
           Version: 9.0.85
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Cluster
          Assignee: dev@tomcat.apache.org
          Reporter: atsushi.okuyama@ip3.co.jp
  Target Milestone: -----

Created attachment 39590
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=39590&action=edit
An app for reproducing.

I have set up a Tomcat cluster using SimpleTcpCluster with channelSendOptions =
"6". (Tomcat version: 9.0.71, 9.0.85)

  Channel.SEND_OPTIONS_SYNCHRONIZED_ACK = 0x0004
  Channel.SEND_OPTIONS_USE_ACK = 0x0002

In my understanding, the http response will not complete until session
replication is complete with channelSendOptions="6".

However, the response completes just before session sharing completes using a
custom response class.

I think the ApplicationDispatcher.doForward method has some issue.

If the response is not an instance of ResponseFacade,
the response writer is closed before session replication starts.

The following is the procedure for reproducing this issue.
The attached WAR is an app for reproducing.

-------------------------------------
(open ports: 4000, 8005, 8080, 14000, 18005, 18080)

(1) Download and create two copies of Apache Tomcat.

$ curl -O
https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.85/bin/apache-tomcat-9.0.85.tar.gz
$ tar -zxf apache-tomcat-9.0.85.tar.gz
$ mv apache-tomcat-9.0.85 apache-tomcat-9.0.85_1
$ cp -rp apache-tomcat-9.0.85_1 apache-tomcat-9.0.85_2


(2) Configure clustering.

$ cp -p server_1.xml apache-tomcat-9.0.85_1/conf/server.xml
$ cp -p server_2.xml apache-tomcat-9.0.85_2/conf/server.xml


(3) Deploy the application for reproduction.

$ cp -p reprod.war apache-tomcat-9.0.85_1/webapps/
$ cp -p reprod.war apache-tomcat-9.0.85_2/webapps/


(4) Start Apache Tomcats.

One as normal and one as debug.

$ ./apache-tomcat-9.0.85_2/bin/startup.sh
$ JPDA_ADDRESS=0.0.0.0:8000 ./apache-tomcat-9.0.85_1/bin/catalina.sh jpda run &


(5) Attach the debugger and set a breakpoint.

Set a breakpoint in the method that replicates the session.

$ jdb -attach 127.0.0.1:8000
> stop in org.apache.catalina.ha.session.DeltaManager.requestCompleted(java.lang.String, boolean)


(6) Open another terminal and visit the URL for the expected behavior.

$ curl http://127.0.0.1:8080/reprod/servlets/expected

The breakpoint has been hit and the curl command is waiting for the response to
complete.
So run the "cont" command in the debugger to continue the process.

http-nio-8080-exec-2[1] cont

The curl command then exits.


(7) Visit the URL that behaves unexpectedly.

$ curl http://127.0.0.1:8080/reprod/servlets/reprod

The debugger stops the thread at the breakpoint, but the curl command exits
immediately.


(8) Stop debugger and tomcats.

> Ctrl-D
$ fg
Ctrl-C
$ ./apache-tomcat-9.0.85_2/bin/shutdown.sh

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 68634] Forwards using custom response classes do not wait for session replication

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68634

--- Comment #2 from Remy Maucherat <re...@apache.org> ---
Ok, the ApplicationDispatcher forward does something different for a
ResponseFacade, so it can mess up your timing. Obviously if the response is
simply a ResponseFacade it gets suspended (pretending to be done) and things
continue nicely, otherwise it gets immediately closed (there is no other way to
enforce the specification requirements that a response is done following a
forward; at this point the client gets the full response and can move on).

Maybe an effort could be made to unwrap and find the ResponseFacade, and only
if not found close. This is really old code.

It is not a good idea to rely too much on this however, since anything in your
app that will close the response would do the exact same behavior. Please use
session pinning instead, to comply with the servlet specification.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 68634] Forwards using custom response classes do not wait for session replication

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68634

--- Comment #4 from OKUYAMA Atsushi <at...@ip3.co.jp> ---
Thank you for your reply. I'm currently considering your responses. Sincerely.

--- Comment #5 from OKUYAMA Atsushi <at...@ip3.co.jp> ---
Thank you for your reply. I'm currently considering your responses. Sincerely.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 68634] Forwards using custom response classes do not wait for session replication

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68634

--- Comment #4 from OKUYAMA Atsushi <at...@ip3.co.jp> ---
Thank you for your reply. I'm currently considering your responses. Sincerely.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 68634] Forwards using custom response classes do not wait for session replication

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68634

Remy Maucherat <re...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #3 from Remy Maucherat <re...@apache.org> ---
I made the change in Tomcat 11 (will be in 11.0.0-M18), however I might not
port it because it is a clear change in behavior. Porting with a flag could be
an option. Anyway, the problem can occur in other scenarios, so your cluster
infrastructure needs to be able to handle it. As a result, I prefer resolving
this as a wontfix.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 68634] Forwards using custom response classes do not wait for session replication

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68634

--- Comment #1 from OKUYAMA Atsushi <at...@ip3.co.jp> ---
Created attachment 39591
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=39591&action=edit
server.xml for reproducing.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org