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

Fix concurrent writing and reading on workers boot #1137

Merged
merged 4 commits into from
Sep 8, 2024

Conversation

wapmorgan
Copy link
Contributor

@wapmorgan wapmorgan commented Sep 4, 2024

Set a shared lock on a file in Memoty::loadData() to prevent reading an empty file while writing it in concurrent worker/process

Q A
Bugfix? ✔️
Breaks BC?
New feature?
Issues Can get an empty file when file_put_contents in \Spiral\Boot\Memory::saveData=>\Spiral\Files\Files::write created, but not completed write to file
Docs PR spiral/docs

Got this problem when 2 jobs consumers concurrently started writing/reading runtime/cache/cycle.php file. First consumer writing schema to the file, second consumers find out that files exists and read it, but it still was empty = so read empty schema.

Set a shared lock on a file in Memoty::loadData() to prevent reading an empty file while writing it in concurrent worker/process
@wapmorgan
Copy link
Contributor Author

wapmorgan commented Sep 4, 2024

Also another option is to remove LOCK_NB and remain only LOCK_SH to force current thread to wait until it will be able to make shared lock.
In current MR's code current thread will build schema again and write it to file again.

Remove `LOCK_NB` flag to make thread waiting for a lock release instead of returning result
@roxblnfk
Copy link
Member

roxblnfk commented Sep 5, 2024

@wapmorgan hi, the first commit was OK. Could you revert the last change?

Revert commit. Dont block current thread
src/Boot/src/Memory.php Outdated Show resolved Hide resolved
src/Boot/src/Memory.php Outdated Show resolved Hide resolved
src/Boot/src/Memory.php Outdated Show resolved Hide resolved
@roxblnfk roxblnfk changed the title Update Memory.php Fix concurrent writing and reading on workers boot Sep 8, 2024
@roxblnfk roxblnfk merged commit bbff436 into spiral:master Sep 8, 2024
11 checks passed
leon0399 added a commit to leon0399/spiral-framework that referenced this pull request Sep 29, 2024
leon0399 added a commit to leon0399/spiral-framework that referenced this pull request Sep 29, 2024
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