Skip to content

EM keeps shutdown when server overloads. #125

@martinbarilik

Description

@martinbarilik

Hi there again. We are using this gem to create client, but we can't figure out why client shutdowns EM immediately if server overloads out client with lots of messages. It happens sporadically once a day or two.

We create client as follows:

Thread.abort_on_exception = true
Thread.new {
  EM.run {
    ws = Faye::WebSocket::Client.new('ws://www.example.com/')

    ws.on :open do |event|
      p [:open]
      ws_logger.info "HELLO!"
    end

    ws.on :message do |event|
      ws_logger.info event.data
    end

    ws.on :close do |event|
      ws_logger.info "#{Time.now} code: #{event.code}, reason: #{event.reason}"
      ws = nil
    end
  }
  EM.add_shutdown_hook { ws_logger.info("#{Time.now} EM SHUTDOWN HOOK") }
}

We need to run client socket in dedicated thread so it won't block anything. Problem starts when server overloads our client with messages, we do not see the messages after overload in ws_logger file, but we have this:

[some time] EM SHUTDOWN HOOK
[some time] code: 1006, reason: 

The fact that EM SHUTDOWN HOOK is first and the socket closes with 1006 tells us, something is wrong. Maybe server sents very big bulk of messages client can't process ?

We have to be able to recover from 1006 and restart web-socket to be running again, but with EM being shutdown, recovery code is killed with it and software stops.

I look some info around sockets, maybe we need to set max_length option to client ? But it buggers me that The default value is 2^26 - 1, or 1 byte short of 64 MiB is not enough ?

I do not know is this is relevant, but i even looked at default buffer size in out machine according to this post https://stackoverflow.com/questions/7865069/how-to-find-the-socket-buffer-size-of-linux.

/proc/sys/net/ipv4/tcp_rmem (for read) // prints 4096    131072  6291456
/proc/sys/net/ipv4/tcp_wmem (for write) // prints 4096    16384   4194304

One more thing, can't figure out what is the difference between this gem and websocket-driver-ruby. Isn't the websocket-driver-ruby more suitable for us ?

If you need more info, ask for it.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions