users@jersey.java.net

[Jersey] SSE client-side closing connection leaves sockets in CLOSE_WAIT.

From: <jvmisc22_at_gmail.com>
Date: Sat, 4 Apr 2015 12:22:53 -0700

Hi all,

I am trying to run a Jersey (v2.17) webapp within tomcat that uses SSE.
Clients are browsers that use JS code to subscribe to events. It's the
default SSE implementation as mentioned in
https://developer.mozilla.org/en-US/docs/Web/API/EventSource


One issue I am noticing is that when the client closes the connection using
eventSource.close(); (JS code) the connections are not closed completely on
the server side. The connections immediately enter the CLOSE_WAIT state and
remain there till the tomcat is restarted. I am guessing that the client
has issued a FIN and the server is still holding on to the connection.

I looked up the Broadcaster code and the onClose method is left to
subclasses to implement, so I sub-classed Broadcaster and overrode the
onClose as shown below

    @Override
    public void onClose(ChunkedOutput<OutboundEvent> chunkedOutput) {
        LOG.info("Client has closed connection...");
        try {
            chunkedOutput.close();
        } catch (IOException e) {
            LOG.error("Error closing eventsource",e);
        }
    }

However I don't see the overridden onClose method getting called when the
client calls close() on the js eventsource object. Is there something
obvious I'm missing here ?

Thanks for your time.
-jv