Skip to content

Commit

Permalink
Freeze alarm message, close orphanes outside synchronize
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMcKin committed May 14, 2016
1 parent 0eba884 commit beda314
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Expand Up @@ -5,6 +5,11 @@ Head
=======
- None yet.

1.0.1
=======
- Close orphan clients outside of synchonize
- Freeze alarm message

1.0.0
=======
- Allow setting a default client for HotTub::Sessions
Expand Down
2 changes: 1 addition & 1 deletion hot_tub.gemspec
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|

s.rubyforge_project = "hot_tub"

s.add_development_dependency "rspec"
s.add_development_dependency "rspec", "~> 3.0"
s.add_development_dependency "rspec-autotest"
s.add_development_dependency "autotest"
s.add_development_dependency "sinatra"
Expand Down
12 changes: 9 additions & 3 deletions lib/hot_tub/pool.rb
Expand Up @@ -234,30 +234,36 @@ def max_size=max_size

private

ALARM_MESSAGE = "Could not fetch a free client in time. Consider increasing your pool size."
ALARM_MESSAGE = "Could not fetch a free client in time. Consider increasing your pool size.".freeze

def raise_alarm
message = ALARM_MESSAGE
HotTub.logger.error message if HotTub.logger
raise Timeout, message
end

def close_orphan(clnt)
HotTub.logger.info "[HotTub] An orphaned client attempted to return to #{@name}." if HotTub.log_trace?
close_client(clnt)
end

# Safely add client back to pool, only if
# that client is registered
def push(clnt)
if clnt
orphaned = false
@mutex.synchronize do
begin
if !@shutdown && @_out.delete(clnt)
@_pool << clnt
else
close_client(clnt)
HotTub.logger.info "[HotTub] An orphaned client attempted to return to #{@name}." if HotTub.log_trace?
orphaned = true
end
ensure
@cond.signal
end
end
close_orphan(clnt) if orphaned
reap! if @blocking_reap
end
nil
Expand Down

0 comments on commit beda314

Please sign in to comment.