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.
WebSocket disconnects can happen by choice, or due to exceptional/error conditions. Here is some information about what happens in each case: Clean disconnect: During a clean disconnect, the user or application will initiate a disconnect sequence.
True but the limit for websockets these days is in the hundreds, as opposed to 6 for regular HTTP requests. https://stackoverflow.com/questions/26003756/is-there-a-limi... It appears to be 30 per domain, not “hundreds”, at least as of the time this answer was written.
A WebSocket connection can in theory last forever. Assuming the endpoints remain up, one common reason why long-lived TCP connections eventually terminate is inactivity.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With