In master, jobs are executed more than once if they have > 1 attempt
One of the last commits in master broke something, and my jobs are executed more than once. It seems to be a race condition, because this happens randomly:
jobs.process('email', 20, function(job, done) {
console.log('start')
// Do something async
setTimeout(function() {
console.log('done')
}, 1000)
})
Jobs of type email have all 2 possible attempts.
Randomly, in my console I either see the correct output (one "start" and then one "end), or
start
start
done
done
Seems like there's a race condition somewhere, so jobs are not marked as in progress before they're started again.
Actually, this happens even if the number of attempts is just 1.
In the UI, I often see things like attempts: 2/1, attempts: 5/3
this is related to ttl feature, will be fixed by next commit
should be fixed
Master is still giving me this issue!
are you sure? provide a log based on job Id. Does the above code generates this?
My bad, my npm-shrinkwrap wasn't updated. Sorry for this
No, actually, the error is still there, after a while.
I don't know why on my tests it wasn't showing up, but now I get 2 emails delivered at the same time, again. On the dashboard, I see the job marked as complete, with "3/2" attempts
wiered... it shouldn't happen.
I've kept updating the code with the last one in master, and I still get this. My jobs fail with "TTL exceeded", even though I didn't set any TTL. I'm using the latest revision in master.
Also, setting a TTL to my jobs (for example, two hours), is simply ignored.
It may help to tell that these jobs are quite "long" (they take ~2 seconds to run).
Here's a test code that demonstrates the issue, running with Kue revision #6f6db5f79fb0e5c7fce4d8e6acba4f137f53a2e9 .
I'm using OSX 10.10, redis-server 2.8.17 (last version available on MacPorts) and Node 0.12.2. I've re-installed all my npm packages so I'm sure kue is installed correctly.
Test code:
'use strict';
let kue = require('kue')
let queue = kue.createQueue({
redis: {
port: 6379,
host: 'localhost',
db: 8
}
})
// Create the auto-signout job
let job = queue.create('long-job', {title: 'long job'})
job.priority('low')
job.attempts(3)
job.searchKeys(['title'])
job.save(function(err) {
if(err) {
throw new Error('Cannot create job: ' + err.toString())
}
})
queue.process('long-job', function(job, done) {
console.log('start')
setTimeout(function() {
console.log('done')
done(null)
}, 5000)
})
Output:
$ node --harmony test-kue.js
start
start
start
done
done
done
// EDIT Updated to Redis 3.0.0 and still not working.
I've kept updating the code with the last one in master, and I still get this. My jobs fail with "TTL exceeded", even though I didn't set any TTL. I'm using the latest revision in master.
I get this error as well.
thank you @EgoAleSum for the test case, will run and let you know
this was a critical BUG, my bad! thank you guys for reporting and improving kue :+1:
Thanks for the fix!
Hey, I'm having a similar issue, so I updated to 0.9.1 in an attempt to fix the issue, but it dosn't look like it worked for me.
I am using the cluster module, and after doing some logging, I am seeing the same job.id being handled by multiple process.pid's. Could this be related? Thanks!
UPDATE: In my case, I have one job that ends up creating a lot of other jobs, and delays each one out by a second more than the last to spread their execution out. During some more testing, it seems like jobs will only be picked up by multiple workers if I'm using the delay feature. Removing the delay seems to fix this particular issue, although it's not suitable for my actual application.
@schnie I think this should be related to #449 and #440 and #443. I've improved delayed job promotion in 0.9, but your claims shows there still exists a race when promoting jobs, which should be here: https://github.com/Automattic/kue/blob/master/lib/kue.js#L188
I think unlock should be called pessimistically after all jobs inactive are done.