Unable to have Server Sent Events (SSE) working properly in Apache + Tomcat

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to have Server Sent Events (SSE) working properly in Apache + Tomcat

raoul.lector
Hi all,

I'm using Apache 2.4.10 on Debian tied with Tomcat 8.0.28.
Tomcat hosts several Web Apps, all routed through a ProxyPass directive (such as ProxyPass /webapp1 ajp://10.10.12.2:8015/webapp1, ProxyPass /webapp2 ajp://10.10.12.2:8015/webapp2, and so on).

My Web Apps works fine, excepted when it comes to broadcast notifications through SSE.
After a few minutes, Tomcat goes crazy, stops serving pages (HTTP 500) and sometimes mixes SSE contents with regular HTML flow.

Important notice : in development environment, all the SSE stuff works perfectly, that is when we run Tomcat without Apache, under Windows 7 / 10.
This detail and what I read in the logs convince me that the problem lies in Apache.

If I'm not wrong, has someone got some hints about the config I should set in Apache ?
Or is Apache definitevely unable to process SSE requests and I should consider moving to NginX ?

Thanks a lot for you help,
Raoul

Additional infos :

        About the Apache's config :
        - Apache 2.4.10 (Debian 64 bits) OpenSSL/1.0.1k
        - mpm-event, with mod_headers, mod_ssl, mod_rewrite, mod_proxy, mod_proxy_http
        - The Tomcat's integration is operated with the mod_proxy_ajp

        About the Web apps config :
        - Tomcat 8.0.28, with java version "1.7.0_79" (OpenJDK 64 bits)
        - The connector is set to use the AJP/1.3 protocol
        - SSE server based upon Jersey 2.5.1

        About the Tomcat logs :
        07-Apr-2019 19:55:19.580 INFO [pool-13-thread-1] org.apache.coyote.AbstractProcessor.setErrorState An error occurred in processing while on a non-container thread. The connection will be closed immediately
        java.io.IOException: Relais brisé (pipe)
        at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
        [...]
        at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:101)
        [...]
        at org.apache.coyote.ajp.AbstractAjpProcessor.action(AbstractAjpProcessor.java:410)
        [...]
        at org.glassfish.jersey.server.Broadcaster.broadcast(Broadcaster.java:150)
        [...]
        at SAR.DTS.Base.b.o.run(ThreadMajRappels.java:58)
        [...]
        at java.lang.Thread.run(Thread.java:745)

        07-Apr-2019 20:10:05.344 INFO [ajp-nio-8015-exec-10] org.apache.catalina.connector.CoyoteAdapter.checkRecycled Encountered a non-recycled response and recycled it forcedly.
        org.apache.catalina.connector.CoyoteAdapter$RecycleRequiredException
        at org.apache.catalina.connector.CoyoteAdapter.checkRecycled(CoyoteAdapter.java:710)
        at org.apache.coyote.ajp.AbstractAjpProcessor.recycle(AbstractAjpProcessor.java:943)
        at org.apache.coyote.ajp.AjpNioProtocol$AjpConnectionHandler.release(AjpNioProtocol.java:163)

        About the Apache logs :
        [Sun Apr 07 20:05:22.338619 2019] [proxy_ajp:error] [pid 6573] [client xx.xx.x.xxx:61445] AH00893: dialog to 10.10.12.2:8015 (10.10.12.2) failed, referer: http://yy.yy.yy.yyy/webapp1
        [Sun Apr 07 20:10:05.344774 2019] [proxy_ajp:error] [pid 6573] [client xx.xx.x.xxx:62693] AH00992: ajp_read_header: ajp_ilink_receive failed, referer: http://yy.yy.yy.yyy/webapp1
        [Sun Apr 07 20:10:05.344783 2019] [proxy_ajp:error] [pid 6573] (120006)APR does not understand this error code: [client xx.xx.x.xxx:62693] AH00878: read response failed from 10.10.12.2:8015 (10.10.12.2), referer: http://yy.yy.yy.yyy/webapp1
        [Sun Apr 07 20:10:05.344745 2019] [proxy_ajp:error] [pid 6573] (104)Connection reset by peer: AH01030: ajp_ilink_receive() can't receive header

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Unable to have Server Sent Events (SSE) working properly in Apache + Tomcat

raoul.lector

Yes, Apache can !
 
I found a way to have SSE working in Apache + Tomcat by replacing the AJP connector with the very simple http one.
 
In Apache config :
# This statment prevents Apache from redirecting to the local URL.
# Oddly, it is unnecessary when using the AJP Connector...
ProxyPreserveHost On
ProxyPass /webapp1 http://10.10.12.2:8016/webapp1 

And in Tomcat config :
<Connector port="8016" protocol="org.apache.coyote.http11.Http11NioProtocol" proxyPort="80"/>

I don't know if this is the right answer to the initial problem, but it gets me closer to the goal...

For now, I'll try 1) to find (if any) the right config for AJP and 2) to have the http config working with SSL and SSE.

----- Mail original -----
De: "raoul lector" <[hidden email]>
À: [hidden email]
Envoyé: Mercredi 10 Avril 2019 15:21:54
Objet: Unable to have Server Sent Events (SSE) working properly in Apache + Tomcat

Hi all,

I'm using Apache 2.4.10 on Debian tied with Tomcat 8.0.28.
Tomcat hosts several Web Apps, all routed through a ProxyPass directive (such as ProxyPass /webapp1 ajp://10.10.12.2:8015/webapp1, ProxyPass /webapp2 ajp://10.10.12.2:8015/webapp2, and so on).

My Web Apps works fine, excepted when it comes to broadcast notifications through SSE.
After a few minutes, Tomcat goes crazy, stops serving pages (HTTP 500) and sometimes mixes SSE contents with regular HTML flow.

Important notice : in development environment, all the SSE stuff works perfectly, that is when we run Tomcat without Apache, under Windows 7 / 10.
This detail and what I read in the logs convince me that the problem lies in Apache.

If I'm not wrong, has someone got some hints about the config I should set in Apache ?
Or is Apache definitevely unable to process SSE requests and I should consider moving to NginX ?

Thanks a lot for you help,
Raoul

Additional infos :

About the Apache's config :
- Apache 2.4.10 (Debian 64 bits) OpenSSL/1.0.1k
- mpm-event, with mod_headers, mod_ssl, mod_rewrite, mod_proxy, mod_proxy_http
- The Tomcat's integration is operated with the mod_proxy_ajp

About the Web apps config :
- Tomcat 8.0.28, with java version "1.7.0_79" (OpenJDK 64 bits)
- The connector is set to use the AJP/1.3 protocol
- SSE server based upon Jersey 2.5.1

About the Tomcat logs :
07-Apr-2019 19:55:19.580 INFO [pool-13-thread-1] org.apache.coyote.AbstractProcessor.setErrorState An error occurred in processing while on a non-container thread. The connection will be closed immediately
java.io.IOException: Relais brisé (pipe)
at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
[...]
at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:101)
[...]
at org.apache.coyote.ajp.AbstractAjpProcessor.action(AbstractAjpProcessor.java:410)
[...]
at org.glassfish.jersey.server.Broadcaster.broadcast(Broadcaster.java:150)
[...]
at SAR.DTS.Base.b.o.run(ThreadMajRappels.java:58)
[...]
at java.lang.Thread.run(Thread.java:745)

07-Apr-2019 20:10:05.344 INFO [ajp-nio-8015-exec-10] org.apache.catalina.connector.CoyoteAdapter.checkRecycled Encountered a non-recycled response and recycled it forcedly.
org.apache.catalina.connector.CoyoteAdapter$RecycleRequiredException
at org.apache.catalina.connector.CoyoteAdapter.checkRecycled(CoyoteAdapter.java:710)
at org.apache.coyote.ajp.AbstractAjpProcessor.recycle(AbstractAjpProcessor.java:943)
at org.apache.coyote.ajp.AjpNioProtocol$AjpConnectionHandler.release(AjpNioProtocol.java:163)

About the Apache logs :
[Sun Apr 07 20:05:22.338619 2019] [proxy_ajp:error] [pid 6573] [client xx.xx.x.xxx:61445] AH00893: dialog to 10.10.12.2:8015 (10.10.12.2) failed, referer: http://yy.yy.yy.yyy/webapp1 
[Sun Apr 07 20:10:05.344774 2019] [proxy_ajp:error] [pid 6573] [client xx.xx.x.xxx:62693] AH00992: ajp_read_header: ajp_ilink_receive failed, referer: http://yy.yy.yy.yyy/webapp1 
[Sun Apr 07 20:10:05.344783 2019] [proxy_ajp:error] [pid 6573] (120006)APR does not understand this error code: [client xx.xx.x.xxx:62693] AH00878: read response failed from 10.10.12.2:8015 (10.10.12.2), referer: http://yy.yy.yy.yyy/webapp1 
[Sun Apr 07 20:10:05.344745 2019] [proxy_ajp:error] [pid 6573] (104)Connection reset by peer: AH01030: ajp_ilink_receive() can't receive header


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]