Bug 54381

Summary: Websocket StreamInbound never reports receipt of a Pong
Product: Tomcat 7 Reporter: David Berkman <david.berkman>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 7.0.34   
Target Milestone: ---   
Hardware: All   
OS: All   

Description David Berkman 2013-01-07 19:44:37 UTC
The tomcat websocket api now allows the send of a Ping frame by the server (as of 7.0.33), via WsOutbound, but never reports the receipt of a Pong. See StreamInbound in the onData() method...

                } else if (opCode == Constants.OPCODE_PONG) {
                    // NO-OP

As the intended use of Pings is for heartbeat messages, allowing a Ping without informing the server extension of the returned Pong leaves out half the utility.

I would suggest these changes to StreamInbound as a fix...

1) In the onData() method...

                } else if (opCode == Constants.OPCODE_PONG) {

2) Add a method onPong (ByteBuffer buffer)...

    protected void onPong(ByteBuffer buffer) {
        // NO-OP

...which implementations may now override to handle Pong receipt and heartbeat logic. This is necessary as onData() is marked final, so there's no alternate workaround.
Comment 1 Mark Thomas 2013-01-08 21:11:13 UTC
Thanks for the report. Fixed in trunk and 7.0.x and will be included in 7.0.35 onwards.

The patch was a little more complex to take account of the class loader issues fixed since 7.0.33.