Skip to content

Fix concurrency issue in BackgroundJob#191

Merged
davidor merged 1 commit intomasterfrom
avoid-class-var-background-job
Apr 15, 2020
Merged

Fix concurrency issue in BackgroundJob#191
davidor merged 1 commit intomasterfrom
avoid-class-var-background-job

Conversation

@davidor
Copy link
Copy Markdown
Contributor

@davidor davidor commented Apr 14, 2020

This PR replaces the usage of a class variable in BackgroundJob.

That class variable causes problems when using the async mode because fibers can modify it while others still need to read it. Luckily, with the current code, the only attribute affected is "enqueue_time", which is not accurate anyway (see #18).

Even without taking the async mode into consideration using a class var is counter-intuitive. The arguments of a particular job (service ID, app ID, etc.) should belong to an instance, they shouldn't be stored in a class var.

This causes problems when using the async mode because all the fibers
share that @Args class var. Luckily, with the current code, the only
attribute affected is "enqueue_time", which is not
accurate anyway (see #18).

Even without taking the async mode into consideration using a class var
is counter-intuitive. The arguments of a particular job (service ID, app
ID, etc.) should belong to an instance, they shouldn't be stored in a class var.
@davidor davidor requested a review from unleashed April 14, 2020 07:40
Copy link
Copy Markdown
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok. You probably did this already, but let's make sure there are no users referencing @args elsewhere in other jobs inheriting from this code.

@davidor
Copy link
Copy Markdown
Contributor Author

davidor commented Apr 15, 2020

Yes, I checked. I didn't see any other usages of @args.

@davidor davidor merged commit e3c5bd2 into master Apr 15, 2020
@bors bors Bot deleted the avoid-class-var-background-job branch April 15, 2020 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants