quartznet-RavenDB icon indicating copy to clipboard operation
quartznet-RavenDB copied to clipboard

Serious bug: a job is deleted even when active triggers remain

Open cadilhac opened this issue 2 years ago • 0 comments

Some time ago, I had reported an issue in the code where the trigger group was used instead of the job group. Here is another instance of the same confusion I discovered when realizing that a job was deleted from the database even if other triggers for the same job were remaining.

Inside RavenJobStore.IJobStore.cs, in RemoveTrigger method, you use:

var hasMoreTriggers = await session
    .Query<Trigger>()
    .Where(t =>
        Equals(t.JobName, job.Key.Name) &&
        Equals(t.Group, job.Key.Group) &&
        !Equals(t.Key, trigger.Key)) // exclude our own since not yet deleted
    .AnyAsync(cancellationToken);

In this code, you compare the trigger group t.Group to the job group!

Since there is no JobGroup property in the trigger entity in the db, one can use the JobKey to fix the query, like this:

var hasMoreTriggers = await session
    .Query<Trigger>()
    .Where(t =>
        Equals(t.JobKey, trigger.JobKey) &&
        !Equals(t.Key, trigger.Key)) // exclude our own since not yet deleted
    .AnyAsync(cancellationToken);

It seems there is another case in the same file where such a confusion exists, but I have not tested it. It's in the TriggersFired method where I see a Equals(t.Group, job.Key.Group) call, comparing an apple and an orange. I hope there is no other instances of the bug somewhere else in the code.

Thanks in advance for bringing the fixes in the master. @ayende ?

cadilhac avatar Aug 29 '22 15:08 cadilhac