Search code examples
javanetwork-programmingjbosscometd

What cometd configurations to use to reduce 402 error occurrences?


We have implemented a Java servlet running on JBoss container that uses CometD long-polling. This has been implemented in a few organizations without any issue, but in a recent implementation there are functional issues which appear to be related to the network setup of this organization.

Specifically, around 5% of the time, the connect requests are getting back 402 errors:

{"id":"39","error":"402::Unknown client","successful":false,"advice":{"interval":0,"reconnect":"handshake"},"channel":"/meta/connect"}

Getting this organization to address network performance is a significant challenge, so we are looking at a way to tune the implementation to reduce these issues.

Which cometd configuration parameters can be updated to improve this? maxinterval, timeout, multiSessionInverval, etc?

Thank you!


Solution

  • The "402 unknown client" error is due to the fact that the server does not see /meta/connect heartbeat messages from the client and expires the correspondent session on the server. This is typically due to network issues.

    Once the client network is restored, the client sends a /meta/connect heartbeat message but the server doesn't have the correspondent session, hence the 402.

    The parameter that controls the server side expiration of sessions is maxInterval, documented here: https://docs.cometd.org/current/reference/#_java_server.

    By default is 10 seconds. If you increase it, it means you are retaining in the server memory sessions for a longer time, so you need to take that into account.