I've made a application which use the Live method in Rails 4. However when I use it every refresh keeps taking one more connection until it reached the maximum of connections to the DB and then just hangs and loads forever.
What can I do to ensure that the connection is brought down when a user refreshes the site or decides to leave it?
This is my setup:
def events
response.headers["Content-Type"] = "text/event-stream"
redis = Redis.new
redis.psubscribe("participants.*") do |on|
on.pmessage do |pattern, event, data|
response.stream.write("event: #{event}\n")
response.stream.write("data: #{data}\n\n")
end
end
rescue IOError
logger.info "Stream closed"
ensure
redis.quit
response.stream.close
end
I use Nginx, with Rainbows! on Ubuntu 10.04. Ruby 2.0.0-p195 Postgresql Rails 4