WebSocket closes after 1000 messages
Asked Answered
H

1

8

I'm writing an app to stream messages to the browser from Apache Kafka using a WebSocket. When the server isn't consuming messages for a while and the offset gets behind, the websocket closes after either 1000 or 2000 messages. The number seems to alternate between the two every test run. Messages are utf8 and usually around 130-140 bytes in length in 8 byte fragments.

When the offset is caught up and messages are coming in at a slightly slower rate, it lasts a lot longer, but will still sometimes close at random after being open for a while.

On the server side I'm using Autobahn with Twisted, this kafka-python library, and just the native WebSocket object on the browser side. Both ends receive the 1006 error code (unexpected close) in every case.

I've currently only tested this with Firefox 31 on RHEL and OSX. The server's python version is 2.6.6. Upgrading would be rather difficult, so unfortunately I can't just see if a new python version fixes it; however if this is definitely the issue it can be done.

The code is very simple at the moment- when the connection opens the server starts consuming Kafka messages and sending them out on the websocket. The client prepends them to the body after adding it to a simple span element with jquery.

Hymnody answered 17/9, 2014 at 17:8 Comment(1)
do you have some code sample for this?Benedetto
U
1

Without a code sample, one of the problems that I can think of is that you are not handling the WebSocket PING / PONG frames and therefore the browser considers the connection inactive at some point.

You could try this: https://github.com/tavendo/AutobahnPython/tree/master/examples/twisted/websocket/ping

Underthecounter answered 28/8, 2015 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.