Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential issues regarding unique jobs #1093

Closed
elridion opened this issue May 29, 2024 · 3 comments
Closed

Potential issues regarding unique jobs #1093

elridion opened this issue May 29, 2024 · 3 comments
Labels
area:oss Related to Oban OSS note:discussion Details or approval are up for discussion

Comments

@elridion
Copy link
Contributor

elridion commented May 29, 2024

Current Behavior

Similar to #1087 and the fix in 2ff529d this is about concurrent inserts of unique jobs in Oban.

When inserting unique jobs the immanent assumption seems to be that

  1. the advisory lock is acquired based on a feasible hash for the given unique constraints, and
  2. if transaction attempt A fails to acquire the lock because transaction B has acquired it, then
  3. its safe to assume that B will commit an insertion that will lead to a conflict and thus A doesn't have to insert one on its own

The thing is, should the transaction B terminate with a rollback the insertion which the lock was acquired for is never committed and in consequence no job will be inserted into the database.
Im not very familiar with using :replace with job insertions but I would guess that there is another issue there since the respective update can't take place.

Expected Behavior

Im not entirely sure how to best handle this but it seems to me that this behaviour is currently pretty obfuscated.
From my perspective this should lead to an error for insert/3,5 and an exception for insert!/3 instead of returning the job as if it was inserted.

@elridion
Copy link
Contributor Author

elridion commented May 29, 2024

Another problem I ran into is that Postgres repeatable read isolation messes with job uniqueness since concurrent transactions are unable to succsesfully SELECT the respective conflicting jobs from each other and thus both jobs will be inserted.

Really no sure how to handle this one but maybe its worth to be noted in the docs.

@sorentwo sorentwo added note:discussion Details or approval are up for discussion area:oss Related to Oban OSS labels May 29, 2024
@sorentwo
Copy link
Owner

There's a lot of thought and discussion about how to handle uniqueness without advisory locks going on currently, partly because of the push for interop with CockroachDB and Yugabyte.

Changing the return to an error in this circumstance may be necessary, but I don't want to introduce a potentially breaking change just to change it again soon. For now, documenting the caveats in the README seems like the best option.

@sorentwo
Copy link
Owner

sorentwo commented Aug 2, 2024

The hybrid and simple unique modes in Oban Pro v1.5 avoid use of advisory locks entirely and aren't susceptible to transaction races.

There won't be any changes to uniqueness in OSS Oban.

@sorentwo sorentwo closed this as completed Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:oss Related to Oban OSS note:discussion Details or approval are up for discussion
Projects
None yet
Development

No branches or pull requests

2 participants