chaps-io / gush

Fast and distributed workflow runner using ActiveJob and Redis
MIT License
1.03k stars 103 forks source link

Possible race condition? #9

Closed romanbsd closed 8 years ago

romanbsd commented 9 years ago

I read the code, and couldn't figure out, how you handle a race condition when job C is dependent on jobs A and B which finish at the same time.

pokonski commented 9 years ago

Are you able to reproduce the issue? A sample code which fails would be helpful. I tested with hundreds of thousands jobs running in parallel (empty jobs to make sure they run and finish at the same time), but the issue never occurred.

Every job has a key in Redis, after the job finishes it gets marked in that key. When A finishes, it marks itself as finished and checks if there are any child jobs with satisfied dependencies. If there are, then it queues them. Same thing with B.

So if A finishes slightly sooner, it doesn't trigger child job since B is running. And if B finishes last, then C's dependencies are satisfied and it gets queued.

romanbsd commented 9 years ago

No, it's a completely theoretical question. I'm still wondering what would happen if they finish at precisely the same time.

pokonski commented 9 years ago

If they do finish at precisely the same time, then it is possible.

That said, I probably should add some mutex to job enqueuing to make sure they don't get enqueued twice. :+1:

Thanks for bringing this up :)

pokonski commented 8 years ago

Closing as this wasn't actually spotted in actual apps using Gush.