Skip to content

Comments

fix: Avoid races for one time jobs#131

Merged
tmccombs merged 1 commit intomasterfrom
races
Feb 13, 2026
Merged

fix: Avoid races for one time jobs#131
tmccombs merged 1 commit intomasterfrom
races

Conversation

@tmccombs
Copy link
Contributor

Fix a race condition in inserting a one-time job.

It could also be avoided by using a "FOR UPDATE" on the select, but I think this solution is cleaner.

Also fix a bug in the test where if we rounded up to the nearest second, the finish time was one second off from the value we compared it to, and the test failed 50% of the time.

@aegbert5

Fix a race condition in inserting a one-time job.

It could also be avoided by using a "FOR UPDATE" on the select,
but I think this solution is cleaner.

Also fix a bug in the test where if we rounded up to the nearest second,
the finish time was one second off from the value we compared it to, and the
test failed 50% of the time.
@tmccombs tmccombs requested a review from hunterrees February 13, 2026 08:39
// Same as "addJob()" but without the finish
val prepared = connection.prepareStatement(
"""
SELECT EXISTS(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hunterrees do you have an opinion on whether we should use INSERT IGNORE, or add a FOR UPDATE for this select?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the INSERT IGNORE is cleaner personally. Makes it easier to follow

Choose a reason for hiding this comment

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

If INSERT IGNORE will work I think that will be better. Cleaner and I believe fewer locks to worry about.

// Same as "addJob()" but without the finish
val prepared = connection.prepareStatement(
"""
SELECT EXISTS(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the INSERT IGNORE is cleaner personally. Makes it easier to follow

// Same as "addJob()" but without the finish
val prepared = connection.prepareStatement(
"""
SELECT EXISTS(

Choose a reason for hiding this comment

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

If INSERT IGNORE will work I think that will be better. Cleaner and I believe fewer locks to worry about.

@tmccombs tmccombs merged commit 6c6ae7e into master Feb 13, 2026
1 check passed
@tmccombs tmccombs deleted the races branch February 13, 2026 17:22
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.

3 participants