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

Session locking problems? #7255

Closed
temp opened this issue Mar 4, 2013 · 3 comments
Closed

Session locking problems? #7255

temp opened this issue Mar 4, 2013 · 3 comments

Comments

@temp
Copy link

temp commented Mar 4, 2013

Try this, on a vanilla symfony-2.2.0

Edit src/Acme/DemoBundle/Controller/SecuredController.php, add sleep(100); to the helloAction.

In your browser, open symfony, access the secured area of the Acme Demo, login as admin.

Open /demo/secured/hello/World, it should load a long time because of the sleep().
Open /demo/secured/hello/admin/World in a second tab.

Now you will see that the second tab will return its response only AFTER the sleep() of the first tab is finished.

Why is this so? Does it happen because of session locking? Or is it a bug?

@temp
Copy link
Author

temp commented Mar 4, 2013

This happens in prod and dev, and only for secured pages.

@mpdude
Copy link
Contributor

mpdude commented Mar 4, 2013

This happens because PHP does session locking. If you have one request with an open PHP session, all other requests for the same session will block in session_start() until the first request finished. More precisely, all requests for that session will be executed one after another.

This is necessary to avoid race conditions - assume both requests were handled in parallel and modified values stored in the session, then PHP would have to bring a merge strategy (which it can't for the general case) or the "last one wins" which is probably not what you want either.

You might want to experiment with session_write_close() or google for "php session concurrency" or the like.

Probably not a Symfony bug, though.

@vicb
Copy link
Contributor

vicb commented Mar 4, 2013

This is indeed the expected behavior as @mpdude mention.

Requests which result in accessing the "Symfony session" are serialized because of the PHP session lock.

You should note however that there is a bug in Symfony for non native storage which do not use a lock, see #4976.

@vicb vicb closed this as completed Mar 4, 2013
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

No branches or pull requests

3 participants