em-websocket icon indicating copy to clipboard operation
em-websocket copied to clipboard

Memory leak trying to memoize websockets

Open AvnerCohen opened this issue 10 years ago • 3 comments

I need to be able to publish data to specific websockets. The full gist of it is: https://gist.github.com/AvnerCohen/72540e2dc13a56b4be87

Specifically I do something like:

  ws.onmessage do |msg|
      event_type, *data = msg.split(":")
      if event_type == 'typing'
        PublishMessage.do(WS_CLIENTS[data.first], "typing:#{data.last}")
        elsif event_type == 'connected'
          WS_CLIENTS_NAME_TO_SOCKET[ws.get_pid] = data.first
          WS_CLIENTS[data.first] = ws
        end
      end

and so, this line:

          WS_CLIENTS[data.first] = ws

Saves the websocket for later reference by username.

this is causing MRI to leak, no idea why, any alternative suggestion to overcome this?

AvnerCohen avatar Mar 04 '15 11:03 AvnerCohen

remove & clear cache when onclose?

JokerCatz avatar Mar 04 '15 17:03 JokerCatz

Sure, this is already happning:

      ws.onclose do
..
          WS_CLIENTS.delete(socket_entry)
..
      end

AvnerCohen avatar Mar 04 '15 18:03 AvnerCohen

hmm...I don't know why , & I fork em-websocket to support long-polling https://github.com/JokerCatz/em-websocket/tree/long_polling_support try it again? , it okay for our production , just overwrite the em-connection :)

JokerCatz avatar Mar 04 '15 19:03 JokerCatz