[Backgroundrb-devel] Bug report: delete_worker breaks begin...ensure (was Re: Canceling work...)

Yves-Eric Martin yem_backgroundrb-devel at filter.yve.net
Sat Feb 23 20:21:41 EST 2008


Hi all, and welcome back John.


John, you may have missed my second reply to you:
http://rubyforge.org/pipermail/backgroundrb-devel/2008-February/001514.html

Anyway, the bad news is: I just tried it out and it does not seem to 
work. delete_worker *is* the "kill -9" hemant suggested.

Hemant, this is breaking some basic Ruby functionality, namely 
"begin...ensure". So can we please call this a bug? delete_worker should 
be a "kill", not a "kill -9", or at least not by default. We could add 
an argument to determine which behavior we want:

# normal "kill" behavior:
MiddleMan.delete_worker(:worker => :background_worker)

# brutal "kill -9" behavior:
MiddleMan.delete_worker(:worker => :background_worker, :kill => true) 



Here is first some code I used in the console to demonstrate in plain 
Ruby what should happen:

##########################################################
  def do_work(args=nil)
    job_exit_status = 'FORCED_EXIT'
    puts "#{Time.now} -- do_work entered"
    begin
      # Large batch job here
      sleep 30
    rescue
      job_exit_status = 'ERRORED_OUT'
      # Error processing here
    else
      job_exit_status = 'FINISHED_NORMALLY'
    ensure
      puts "#{Time.now} -- do_work exit status: #{job_exit_status}"
    end
  end
##########################################################


If Ctrl-C is pressed before completion, here is what we get:

 >> do_work
2008-02-24 10:12:03 -- do_work entered
2008-02-24 10:12:04 -- do_work exit status: FORCED_EXIT



Now here is the BackgrounDRb code used to show the bug:

##########################################################
class BackgroundWorker < BackgrounDRb::MetaWorker
  set_worker_name :background_worker
  def create(args = nil); end
  def do_work(args=nil)
    job_exit_status = 'FORCEABLY_DELETED'
    logger.info "#{Time.now} -- do_work entered"
    begin
      # Large batch job here
      sleep 30
    rescue
      job_exit_status = 'ERRORED_OUT'
      # Error processing here
    else
      job_exit_status = 'FINISHED_NORMALLY'
    ensure
      logger.info "#{Time.now} -- do_work exit status: #{job_exit_status}"
    end
  end
end
##########################################################

If allowed to finish, we get this in the logs:
2008-02-24 09:45:37 -- do_work entered
2008-02-24 09:45:47 -- do_work exit status: FINISHED_NORMALLY

However, if delete_worker is called before completion, we only get:
2008-02-24 09:46:03 -- do_work entered



Cheers,

-- 
Yves-Eric



More information about the Backgroundrb-devel mailing list