Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release db connections after each callback. #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/tubesock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,18 @@ def listen
Thread.new do
Thread.current.abort_on_exception = true
@open_handlers.each(&:call)
release_db_connections
each_frame do |data|
@message_handlers.each{|h| h.call(data) }
release_db_connections
end
close
end
end

def close
@close_handlers.each(&:call)
release_db_connections
@socket.close unless @socket.closed?
end

Expand All @@ -91,6 +94,10 @@ def keepalive
end

private
def release_db_connections
ActiveRecord::Base.clear_active_connections! if defined? ActiveRecord
end

def each_frame
framebuffer = WebSocket::Frame::Incoming::Server.new(version: @version)
while IO.select([@socket])
Expand Down