Skip to content

TimerTask doesn't timeout #677

@divanikus

Description

@divanikus

Consider the following code

#!/usr/bin/env ruby
require "concurrent"

class TaskObserver
  def update(time, result, ex)
    if ex.is_a?(Concurrent::TimeoutError)
      print "(#{time}) Execution timed out\n"
    end
  end
end

puts "Creating tasks"
10.times do |x|
  task = Concurrent::TimerTask.new(run_now: true, execution_interval: 20, timeout_interval: 5) do
    sleep x*2
    puts "#{x*2} finished"
  end
  task.add_observer(TaskObserver.new)
  task.execute
end

sleep 60
puts "Terminated"

Expected behaviour:

Creating tasks  
0 finished      
2 finished      
4 finished      
(2017-10-19 00:57:48 +0300) Execution timed out
(2017-10-19 00:57:48 +0300) Execution timed out
(2017-10-19 00:57:48 +0300) Execution timed out
(2017-10-19 00:57:48 +0300) Execution timed out
...

Real behavior:

Creating tasks
0 finished
2 finished
4 finished
6 finished
8 finished
10 finished
12 finished
14 finished
16 finished
18 finished
...

  • Operating system: linux
  • concurrent-ruby version: 1.0.5
  • concurrent-ruby-ext installed: no
  • concurrent-ruby-edge used: no

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug in the library or documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions