jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

Supporting SSE with AsyncMiddleManServlet

Open rushalias opened this issue 5 years ago • 5 comments
trafficstars

Opening a ticket per Simone’s suggestion.

Application details:

OS: Ubuntu 18.04.3 LTS JRE: OpenJDK 64-Bit Server VM Corretto-11.0.6.10.1 Jetty: 9.4.26.v20200117

Issue:

We are running a reverse proxy based on Jetty's AsyncMiddleManServlet. Lately, a new use case has emerged where a backend sends out Server Sent Events (SSE). In particular, we are trying to reverse proxy calls to spring-boot-admin, in particular calls returning a stream of SSE (eg.InstancesController.java)

There is this recommendation, https://github.com/eclipse/jetty.project/issues/3459, which is to add a flush call in ProxyServlet.onResponseContent(). However, this seems to be a bit of a problem for us since we are using/subclassing AsyncMiddleManServlet and can not find the proper place to cut in with a flush() call.

Currently, we have it implemented in newServerResponseContentTransformer with Identity as the transformer, but this does not seem the right place to hook in the call for a flush.

@Override
protected ContentTransformer newServerResponseContentTransformer(
    HttpServletRequest clientRequest, 
    HttpServletResponse proxyResponse, 
    Response serverResponse)
{
    return (input, finished, output) -> {
        output.add(input); // Identity content transformer
        if ( is this SSE ) {
            proxyResponse.getOutputStream().flush();
        }
    };
}

We have deployed this in our pre-production environment and spring boot admin UI seems to work fine and is responsive.

A couple of questions:

  • Is this the right place to cut in for the flush call?
  • If ^^ is not the correct place to cut in, then where would you suggest we add the proposed flush call to support SSE in AsyncMiddleManServlet?

Thank you in advance for your help. -Lu

rushalias avatar May 13 '20 04:05 rushalias

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 02 '21 17:06 stale[bot]

I come across this issue already twice as my attempts to get AsyncMiddleManServlet working with SSE failed. I did revert to plain ProxyServlet with forced flush inside ProxyServlet.onResponseContent when x-accel-buffering is set to no. Apparently content transformer is not a valid place to force flush as in my case. Fix suggested in this issue leaves my browser without events (result is either HTTP 504 or HTTP 200 without data).

splatch avatar Jun 07 '21 22:06 splatch

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jun 08 '22 00:06 github-actions[bot]

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jun 09 '23 00:06 github-actions[bot]

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jun 10 '24 00:06 github-actions[bot]

This issue has been closed due to it having no activity.

github-actions[bot] avatar Jul 10 '24 00:07 github-actions[bot]