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

Avoid race-condition when reading localeCollection #3435

Conversation

christianharrington
Copy link
Contributor

@christianharrington christianharrington commented Jan 16, 2025

The previous implementation was an example of a check-then-act race-condition: There is no guarantee that the cached value still exists when it is subsequently read out.

This would cause errors later when $this->localeCollection could suddenly have the value false.

See #3188 for more context.

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

The previous implementation was an example of a check-then-act
race-condition: There is no guarantee that the cached value still exists
when it is subsequently read out.

This would cause errors later when `$this->localCollection` could
suddenly have the value `false`.
@github-actions github-actions bot added the 8.3 label Jan 16, 2025
Copy link
Member

@kdambekalns kdambekalns left a comment

Choose a reason for hiding this comment

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

Seems edge-casey to me, but totally makes sense.

@kdambekalns
Copy link
Member

Just the tests need to be adjusted…

@christianharrington
Copy link
Contributor Author

Seems edge-casey to me, but totally makes sense.

This was happening many times a day in production for us before we implemented a mitigation 🤷🏻

Just the tests need to be adjusted…

Yeah, sorry, I had difficulty figuring out how to run them locally. I couldn't find any documentation on it, so I ended up reverse-engineering it from the Github Actions workflow.

I found the error raised in the test quite confusing as well:

Expectation failed for method name is "addLocale" when invoked 4 time(s).

The issue was in fact the method name being used for the mocked cache 🤔

Copy link
Member

@markusguenther markusguenther left a comment

Choose a reason for hiding this comment

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

Thanks for bringing that up again! Sorry I missed it yesterday with the tests and was too quick with the merge since it worked locally. 😅

Thanks for your contribution, and it’s great to hear that you still use Flow at famly.

@markusguenther markusguenther merged commit f9ce79a into neos:8.3 Jan 16, 2025
9 checks passed
@christianharrington christianharrington deleted the bugfix/cached-collection-race-condition branch January 16, 2025 13:18
@kdambekalns
Copy link
Member

This was happening many times a day in production for us before we implemented a mitigation

Doh. Ok, to me it seems that cache should exist rather reliably… 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants