nicolasff / webdis

A Redis HTTP interface with JSON output
https://webd.is
BSD 2-Clause "Simplified" License
2.82k stars 307 forks source link

Epoll MOD Bad file descriptor #125

Open azman0101 opened 8 years ago

azman0101 commented 8 years ago

Hello, I've got this error when trying to send 2 request in a row with WebSocket.

[warn] Epoll MOD(1) on fd 133 failed.  Old events were 6; read change was 0 (none); write change was 2 (del): Bad file descriptor
                jsonSocket.send(data1);
                jsonSocket.send(data2);

Then, webdis is unable to handle other request (failed: WebSocket opening handshake timed out)

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff75b2700 (LWP 6323)]
0x0000000000413ce0 in __redisAsyncCommand (ac=0x0, fn=0x40a9ab <json_reply>, 
    privdata=0x7ffff0005310, 
    cmd=0x7ffff0005928 "*4\r\n$5\r\nHMSET\r\n$22\r\n1234567894_azman0101r\r\n$9\r\ntimestamp\r\n$13\r\n1451140994807\r\n", len=79) at hiredis/async.c:593
593     if (c->flags & (REDIS_DISCONNECTING | REDIS_FREEING)) return REDIS_ERR;
azman0101 commented 8 years ago

There is the backtrace:

#0  0x0000000000414a2e in __redisAsyncCommand (ac=0x0, 
    fn=0x40a9eb <json_reply>, privdata=0x7ffff0004e80, 
    cmd=0x7ffff00055c8 "*3\r\n$5\r\nRPUSH\r\n$10\r\n123456789\r\n$21\r\nazman0101_datadatadata\r\n", len=60) at hiredis/async.c:594
#1  0x0000000000414e7b in redisAsyncCommandArgv (ac=0x0, 
    fn=0x40a9eb <json_reply>, privdata=0x7ffff0004e80, argc=3, 
    argv=0x7ffff0004d10, argvlen=0x7ffff0004f00) at hiredis/async.c:679
#2  0x0000000000402cb8 in cmd_send (cmd=0x7ffff0004e80, 
    f_format=0x40a9eb <json_reply>) at cmd.c:284
#3  0x0000000000408c8b in ws_execute (c=0x62c930, 
    frame=0x7ffff0004f90 "[\"RPUSH\",\"123456789\",\"azman0101_datadatadata\"]", frame_len=46) at websocket.c:212
#4  0x00000000004090fd in ws_add_data (c=0x62c930) at websocket.c:314
#5  0x00000000004030c6 in worker_can_read (fd=53, event=2, p=0x62c930)
    at worker.c:58
#6  0x00007ffff7ba3f24 in event_base_loop ()
   from /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5
#7  0x0000000000403489 in worker_main (p=0x62c070) at worker.c:158
#8  0x00007ffff7980182 in start_thread (arg=0x7ffff75b2700)
    at pthread_create.c:312
#9  0x00007ffff76ad47d in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
azman0101 commented 8 years ago

Can anybody tell me why ac passed to redisAsyncCommandArgv is NULL ?

azman0101 commented 8 years ago

This is the javascript code:

function update_redis(id_str, screen_name) {
  try {
      var jsonSocket = new WebSocket("ws://127.0.0.1:7379/.json");

      jsonSocket.onopen = function() {
          console.log("JSON socket connected!");
          var userlog = JSON.stringify(["RPUSH", id_str, screen_name + "_" + String(Date.now())]);
          console.log("Push this user to log!" + userlog);
          jsonSocket.send(userlog);
      };
      jsonSocket.onmessage = function(messageEvent) {
          console.log("JSON received:", messageEvent.data);
      };
      jsonSocket.onclose = function()
         { 
            // websocket is closed.
          console.log("JSON socket closed!");
         };

  } catch ( e ) {
      console.warn(e);
  }
}
washtubs commented 6 years ago

I'm seeing the same issue:

[warn] Epoll MOD(1) on fd 133 failed. Old events were 6; read change was 0 (none); write change was 2 (del); close change was 0 (none): Bad file descriptor

Pasting in the websocket example from the README

function testJSON() {
    var jsonSocket = new WebSocket("ws://127.0.0.1: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);
    };
}
testJSON();

shows only

JSON socket connected!
JSON received: {"SET":[true,"OK"]}

The message for JSON received: {"GET":"world"} is not seen.