-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix duplicate trigger creation race condition (#20699)
The process for queueing up a trigger, for execution by the TriggerRunner, is handled by the TriggerJob's `load_triggers` method. It fetches the triggers that should be running according to the database, checks if they are running and if not it adds them to `TriggerRunner.to_create`. The problem is tha there's a small window of time between the moment a trigger (upon termination) is purged from the `TriggerRunner.triggers` set, and the time that the database is updated to reflect the trigger's doneness. If `TriggerJob.load_triggers` runs during this window, the trigger will be added back to the `TriggerRunner.to_create` set and it will run again. To resolve this what we do here is, before adding a trigger to the `to_create` queue, instead of comparing against the "running" triggers, we compare against all triggers known to the TriggerRunner instance. When triggers move out of the `triggers` set they move into other data structures such as `events` and `failed_triggers` and `to_cancel`. So we union all of these and only create those triggers which the database indicates should exist _and_ which are know already being handled (whatever state they may be in) by the TriggerRunner instance.
- Loading branch information
Showing
2 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters