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 written when only read causing parallel issues #26

Open
twiggy opened this issue Jan 6, 2015 · 1 comment
Open

Session written when only read causing parallel issues #26

twiggy opened this issue Jan 6, 2015 · 1 comment

Comments

@twiggy
Copy link

twiggy commented Jan 6, 2015

I have an app that calls multiple requests in parallel. One of the requests simply reads the session in order to track information while the next request actually posts information to the session. Given that we have many servers these request might not execute in the right order. What can happen is the request that only reads the session can overwrite the seconds requests set with stale data if they execute together just the right way.

Making the requests serial is not ideal as it is pretty much a fire and forget type event from the front ends perspective.

My app already explicitly calls beaker's persist() method when session variables are written. This prevents some of these issues.

On line 30 in init.py there is self.persist() and the "if" that drives it uses self.accessed() which I think is being flipped if the session variable is read.

I've hacked my code to reproduce the issue consistently which was fairly intermittent normally. Commenting out the persist on line 30 makes the issue go away.

I notice a pretty explicit comment about beaker's "auto" configuration option in the call_save method. From my perspective I need to control the sessions write explicitly. I'd like to somehow have this extension honor the auto option of beaker although I see this as probably breaking backwards compatibility of this plugin.

I'm happy to put together a pull request if you'd let me know how you'd prefer this be implemented. If you'd rather it not get implemented I'll just fork in some fashion.

I'm thinking that in call_save we could keep track of a dirty variable. Only if one of the dictionary modifying functions has been called do we call persist on line 30. call_save() will set a variables say session._pyramid_session_dirty = True given that _dirty might have a name conflict.

I tried changing self.accessed to self.dirty, but that didn't seem to fix it. Looking at beaker code that doesn't seem reliable anyways. I couldn't find a way to see if the session had actually been modified vs just read in beaker. Accessed seems to only be if it got loaded up.

Thanks!

@fschulze
Copy link
Contributor

fschulze commented Apr 5, 2024

I released pyramid-beaker 0.9 which should fix this

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

2 participants