Skip to content

Commit

Permalink
fix for NonLocalJump out of thread when shutting down in ext/c_zookee…
Browse files Browse the repository at this point in the history
…per.rb
  • Loading branch information
slyphon committed Apr 25, 2012
1 parent 376e681 commit b500456
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions ext/c_zookeeper.rb
Expand Up @@ -135,32 +135,30 @@ def wait_until_running(timeout=5)
end

def setup_event_thread!
@event_thread ||= Thread.new do
Thread.current.abort_on_exception = true # remove this once this is confirmed to work
@event_thread ||= Thread.new(&method(:_event_thread_body))
end

logger.debug { "event_thread waiting until running: #{@_running}" }
def _event_thread_body
logger.debug { "event_thread waiting until running: #{@_running}" }

@start_stop_mutex.synchronize do
@running_cond.wait_until { @_running }
@start_stop_mutex.synchronize do
@running_cond.wait_until { @_running }

if @_shutting_down
logger.error { "event thread saw @_shutting_down, bailing without entering loop" }
return
end
if @_shutting_down
logger.error { "event thread saw @_shutting_down, bailing without entering loop" }
return
end
end

logger.debug { "event_thread running: #{@_running}" }
logger.debug { "event_thread running: #{@_running}" }

while true
begin
_iterate_event_delivery
rescue GotNilEventException
logger.debug { "#{self.class}##{__method__}: event delivery thread is exiting" }
break
end
while true
begin
_iterate_event_delivery
rescue GotNilEventException
logger.debug { "#{self.class}##{__method__}: event delivery thread is exiting" }
break
end

# TODO: should we try iterating events after this point? to see if any are left?
end
end

Expand Down

0 comments on commit b500456

Please sign in to comment.