-
Notifications
You must be signed in to change notification settings - Fork 31
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 Connector from session constructor #460
Conversation
In some race condition, seems the session.get return the Connector instance, not a serialize version of the instance. Fix ome#459
Hi @gaelrayot-epfl - thanks for the bug report and fix. Change looks good.
For the GPL-licensed OME projects, I must ask you to fill out a Contributor's License Agreement as described at https://ome-contributing.readthedocs.io/en/latest/cla.html before we can accept your PR. Thanks |
Interestingly, this upgrade issue was not detected on IDR where OMERO.web has been recently upgraded to OMERO.web 5.18.0. I suspect the reason is because IDR uses a blue-green deployment strategy which means it does not leave any session. I was able to reproduce the issue by using one of the IDR pilot dev systems. After downgrading OMERO.web 5.17.0, logging in as the public user, and running
refreshing the browser suffices to instantaneously trigger the exception raised in #459. Opening the webclient in a separate browser works without issue i.e. it does not try to use the pre-upgrade session and creates a new connection. I was able to reproduce the output described by Will in #460 (comment) after downgrading and re-upgrading OMERO.web to the HEAD of this PR
The webclient reloaded without issue but fails quickly when trying to access a key from If the goal is to upgrade existing sessions, would it make sense to upgrade the serialized objet as well i.e. make an additional |
Hi @will-moore I've just sent you the CLA form. Thanks. |
Actually, I realise that I'm not even sure we really need the |
@@ -281,6 +281,8 @@ def from_session(request): | |||
v = request.session.get("connector", None) | |||
if v is None: | |||
return None | |||
if isinstance(v, Connector): | |||
return v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As shown by the testing, one of the issue of trying to re-use an existing Connector
object from a previous (pre-upgrade) session is that it leaves other objects like request.session["connector"]
in a state incompatible with the assumptions of the OMERO.web code.
#435 discusses other scenarios which might lead to similar incompatible states e.g. switching between different session serializers. From a discussion with @chris-allan, we probably need to be more defensive in OMERO.web, catch these scenarios and ensure a new session get created. From the user perspective, this will either happen automatically if the public user is configured or redirect to the login page.
Specifically in that case, could we catch the scenarios where v
is not a dictionary that can be used to instantiate a Connector
and return None
with a logging statement (warn?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another suggestion: reset the session connector as JSON here:
if isinstance(v, Connector):
v.to_session(request)
return v
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: https://forum.image.sc/t/error-retrieving-connection/80230/2 |
A less intrusive solution would be to be able to clear all the sessions during the upgrade from <5.18 to >=5.18 right? |
@gaelrayot-epfl conceptually, fully agreed that an API to clear all sessions during an OMERO.web upgrade would be the most robust way to resolve such issue. The initial hope was that this would happen out of the box as omero-web/omero/plugins/web.py Lines 528 to 531 in b3a74ac
|
In addition to what is outlined in #435 as detailed by @sbesson above, the potential problems are likely to get worse as we begin to support the 4.x series of Django which has been started in #458. Django 4.x drops support for pre-3.1 encoded sessions 1 so if you're making a big version jump things will be really uncomfortable. Support for pickled sessions was already deprecated in 4.1 and will be removed from Django entirely when 5.0 is released. Session storage is not something I think most OMERO administrators consider when performing an upgrade. We're going to need documentation to coach those administrators on session compatibility between major versions and make them more aware of the storage and serialization realities they are exposed to. We'll also need code to help them not get themselves in trouble or have to cook up their own methods to expire or destroy sessions across the variety of backends we encourage people to use. See also: Footnotes |
So, let's say my OMERO.Web is configured as followed:
I could simply delete all the redis entries matching sessions. Sorry this does not help you fixing all the new session management but I've an upgrade to do tomorrow and I want it to be as smooth as possible for the users. |
Correct. |
Before you do anything I would recommend backing up what is currently in your Redis database just in case. Based on your configuration and if you are confident you only have Django sessions in Redis database If you want to see all your keys you would run Alternatively, you can find the prefix for all the sessions stored in Redis (it should be something like
Again, be careful with this. |
Yes, I've just check the keys in the DB, it's only sessions for now. Thank you. |
FYI clearing the Redis sessions does not fix the issue. |
I'm not sure how this could be the case based on how the code functions. Could you let us know what process you followed? What OMERO.web plugins do you have installed? |
On a public instance, without being logged, once I upgrade from 5.16.0 to 5.19.0, then reload, I get the same message. There wasn't any session stored in redis. The omero plugins:
|
Did you shut OMERO.web 5.16.0 down entirely and ensure all the processes are stopped, then run the Redis database clean, perform the upgrade to 5.19.0 and then start OMERO.web back up? |
Yes
|
@gaelrayot-epfl could you paste the output of Update: using a test instance configured with Redis cache (
In both cases, trying to re-use an existing session in the browser or refreshing it leads either the exception reported in #459 for a public session or a similar one for an authenticated user session. Introducing an intermediate step clearing all sessions in Redis fixes both errors. In the authenticated user session case, this redirects you to the login page as the session has disappeared. In the public session case, a new session gets automatically recreated in the background
|
Heyo, I upgraded today to OMERO.server 5.6.7 and also OMERO.web 5.20.0. PS: Maybe worth to mention we also have a |
Closing for now; will revisit if it turns out that clearing the session store does not always resolve the issue. |
In some race condition, seems the session.get return the Connector instance, not a serialize version of the instance.
Fix #459