Skip to content

[HttpFoundation] use atomic writes in MockFileSessionStorage #39816

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

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #39167
License MIT
Doc PR -

Instead of #39808

@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Jan 13, 2021
@nicolas-grekas nicolas-grekas changed the title Rename normalize param [HttpFoundation] use atomic writes in MockFileSessionStorage Jan 13, 2021
Copy link
Member

@jderusse jderusse left a comment

Choose a reason for hiding this comment

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

We should also handle concurency in read method: is_file($filePath) ? file_get_contents($filePath) given the file could be deleted in the meantime (see #39167 (comment))

@nicolas-grekas
Copy link
Member Author

Unless we have reports that this happens IRL, I think we should fix as little as possible. The linked report is only about non-atomic writes. I'd wait before doing more on this topic.

@jderusse
Copy link
Member

Unless we have reports that this happens IRL,

I felt like the linked comment reported by @mpdude were a real case.

@nicolas-grekas
Copy link
Member Author

I felt like the linked comment reported by @mpdude were a real case.

It is, and the message there is about "Notice: unserialize()". That's unrelated to the is_file() check you're mentioning for now.

@mpdude
Copy link
Contributor

mpdude commented Jan 13, 2021

Over here, I also mentioned that the unlink() call may be a source of errors as well, since the file might have been deleted by another process in the meantime.

@nicolas-grekas
Copy link
Member Author

OK, thanks for the link. So you have processes that concurrently destroy the session?
That cannot work of course, whatever we do here, there will always be an issue with concurrent requests that read and destroy at the same time.
You should not destroy concurrently to me.

@nicolas-grekas
Copy link
Member Author

Now updated to guard against concurrent unlink().

@mpdude
Copy link
Contributor

mpdude commented Jan 13, 2021

Regarding @jderusse's comment above, the is_file($filePath) ? file_get_contents($filePath) concurrency thing could also be addressed with something like

        set_error_handler(static function () {});
        try {
            $this->data = [];
            $this->data = unserialize(file_get_contents($filePath));
        } finally {
            restore_error_handler();
        }

But regardless of that, 👍 and thanks for the fix!

@nicolas-grekas
Copy link
Member Author

the is_file($filePath) ? file_get_contents($filePath) concurrency thing

code updated

@solverat
Copy link

@nicolas-grekas i just merged your PR into my largest test-set, and it's still passing! Thank you!

@nicolas-grekas nicolas-grekas merged commit 9c6381c into symfony:4.4 Jan 14, 2021
@nicolas-grekas nicolas-grekas deleted the mock-sess-atomic branch January 20, 2021 19:45
This was referenced Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants