3

I'm using Redis + Webdis on Debian 7 32.

My issue is that all websocket connections are closed with the exit code 1006 after completing the first command (except the "SUBSCRIBE" one). For example, for this testJSON() function

function testJSON() {
  var jsonSocket = new WebSocket("ws://ip:7379/.json");
  jsonSocket.onopen = function() {
    console.log("JSON socket connected!");
    jsonSocket.send(JSON.stringify(["SET", "hello", "world"]));
    jsonSocket.send(JSON.stringify(["GET", "hello"]));
  };
  jsonSocket.onmessage = function(messageEvent) {
    console.log("JSON received:", messageEvent.data);
  };
  jsonSocket.onclose = function(messageEvent) {
    //some logging
  };
  jsonSocket.onerror = function(messageEvent) {
    //some logging
  };
}
testJSON();

i'm getting (in Firebug)

JSON socket connected!
JSON received: {"SET":[true,"OK"]}
onClose: error.code 1006

The onError event is'nt working, and after the {"SET":[true,"OK"]} response my connection closes. GET command is'nt working too. Same behavior in Firefox and Chrome. I checked the headers, it seems they are valid.

Any suggestions?

Paul
  • 26,170
  • 12
  • 85
  • 119
Andrew Roo
  • 61
  • 1
  • 2
  • 5
  • 1
    1006 is a special code that means the connection was closed abnormally (locally) by the browser implementation. I tried your example and changed server to ws://echo.websocket.org it seems to be working fine. Whats the version of your browser? can you try to connect to echo.websocket.org and chk whether you still get disconnected. – Jack Daniel's Mar 26 '14 at 08:35
  • Hi. TY, connection to ws://echo.websocket.org works well, without any problems. I had some suggestions about incorrect server responses, but it seems that webdis cannot log websocket actions. I use FF 27.0.1 – Andrew Roo Mar 26 '14 at 09:35

1 Answers1

3

Ok, it's a feature, not bug. In code (websocket.c):

if (cmd_is_subscribe(cmd)) {
    r->keep_alive = 1;
}

Changing this code solved part of my problems, but not all of them.

Community
  • 1
  • 1
Andrew Roo
  • 61
  • 1
  • 2
  • 5
  • It does look like webdis keeps the websocket connections open only for (p)subscribe commands. Clients are expected to open one persistent subscribe/listening connection, and open a separate connection for each publish/set/get command then? Best use ajax for the other non-subscribe commands then, less http-upgrade ws overhead to go through. – init_js Aug 12 '19 at 23:26