Skip to content

fix: fixes more race conditions with transactions - #4164

Merged
DanRibbens merged 4 commits into
payloadcms:mainfrom
diesieben07:more-transaction-fixes
Nov 20, 2023
Merged

DanRibbens merged 4 commits into
payloadcms:mainfrom
diesieben07:more-transaction-fixes

Conversation

@diesieben07

@diesieben07 diesieben07 commented Nov 15, 2023 •

Copy link
Copy Markdown
Contributor

Description

This pull request fixes two race conditions with transactions:

  1. A toc/tou issue in initTransaction, which can lead two operations to both initialize a transaction and both think they are in charge of committing it.
  2. A race condition in all operations that use getEntityPolicies. These operations did not start a transaction, and so the many operations that getEntityPolicies kicks off concurrently were racing for who starts and commits the transaction.
  • I have read and understand the CONTRIBUTING.md document in this repository.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have added tests that prove my fix is effective or that my feature works
  • Existing test suite passes locally with my changes

@DanRibbens DanRibbens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From what I can tell this is exactly what we need having that req.transactionIDPromise. I would like to introduce a test suite called database under which we can add a some transaction specific int cases using just the local api that:

  • multiple operations from one req async
  • multiple operations from one req sync
  • one successful operation, call another that fails and expect the rollback of the first operation

@diesieben07

Copy link
Copy Markdown
Contributor Author

I will try to write a test suite that tests this, yes. I didn't do that yet, because I am not quite sure ho exactly to accomplish it. But I'll give it a shot tomorrow!

@DanRibbens

Copy link
Copy Markdown
Contributor

Hey @diesieben07, I can probably sink a few mins in here and have it done. If you don't have this started, I can jump on it. Let me know!

@diesieben07

Copy link
Copy Markdown
Contributor Author

@DanRibbens I appreciate the help, yes please go ahead! Unfortunately I did not have time to work on this yesterday and today and I'll be busy on the weekend, too.

@DanRibbens
DanRibbens merged commit 1510baf into payloadcms:main Nov 20, 2023
@DanRibbens

Copy link
Copy Markdown
Contributor

@diesieben07 Thank you so much for all the help with transaction stability!

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