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

Shared multitask prerequisite intermittently executed multiple times #274

Open
ilpon opened this issue Oct 1, 2018 · 1 comment
Open

Comments

@ilpon
Copy link

ilpon commented Oct 1, 2018

Given a Rakefile

multitask :default => [:a, :b, :c, :d, :e]

task :a => ['target']
task :b => ['target']
task :c => ['target']
task :d => ['target']
task :e => ['target']

rule(/^target$/ => [ 'source' ]) do |t|
    p "#{t.name} => #{t.source}"
    p t.actions
end

file 'source'

the target may get executed multiple times like this

$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-musl]
$ rake --version
rake, version 12.3.1
$ rake --trace --rules
** Invoke default (first_time)
** Invoke a (first_time)
Attempting Rule target => source
** Invoke b (first_time)
Attempting Rule target => source
** Invoke c (first_time)
Attempting Rule target => source
** Invoke d (first_time)
Attempting Rule target => source
(target => source ... EXIST)
** Invoke e (first_time)
Attempting Rule target => source
(target => source ... EXIST)
(target => source ... EXIST)
** Invoke target (first_time)
(target => source ... EXIST)
** Invoke source (first_time)
(target => source ... EXIST)
** Execute source
** Execute target
"target => source"
[#<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>]
"target => source"
[#<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>]
"target => source"
[#<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>]
"target => source"
[#<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>]
"target => source"
[#<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>, #<Proc:0x000055e092b971c0@/repo/Rakefile:10>]
** Execute d
** Invoke target 
** Execute b
** Invoke target 
** Execute a
** Invoke target 
** Execute c
** Invoke target 
** Execute e
** Execute default

The results differ between runs. It seems to happen more often with debug output.

The same action block gets added multiple times to the same task.

@ilpon
Copy link
Author

ilpon commented Oct 2, 2018

Workaround:

LOOKUP_MONITOR = Monitor.new
module RakeTaskManagerPatch
    def [](task_name, scopes=nil)
        self.lookup(task_name.to_s, scopes) or LOOKUP_MONITOR.synchronize { super(task_name, scopes) }
    end
end
class Rake::Application prepend RakeTaskManagerPatch end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant