ngauthier / tubesock

Websocket interface on Rack Hijack w/ Rails support
MIT License
620 stars 43 forks source link

On close callback continues to run after closing socket #6

Closed kennylovrin closed 11 years ago

kennylovrin commented 11 years ago

I am experiencing some strangeness while playing around with Tubesock. I have some very basic code, very similar to the example app.

It seems to me that when I reload the browser so that the open socket is closed and a new one is opened, the app then continues to call the on close callback over and over forever. It seems as if it calls it every times it pings a closed socket, but I am not totally sure exactly what causes this.

Just to test, I just put the following code in an initializer, and it does stop the callback from being called, but I am still not sure if it actually properly stops and releases the closed socket.

class Tubesock
  def keepalive
    Thread.new do
      Thread.current.abort_on_exception = true
      loop do
        sleep 5
        Thread.current.exit if @socket.closed?
        ping
      end
    end
  end
end
ngauthier commented 11 years ago

Thanks for the report! I've fixed this in tubesock 0.2.2. I added a close handler within tubesock to kill the keepalive thread.

xoxo <3 @ngauthier