-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Wrongly deleted sessions #6749
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
Comments
|
Unfortunately not, we can't find any pattern |
@dplewis Sure, please go ahead. @SebC99 Could it be some external reason? I am thinking of an iOS setting that uninstalls apps automatically when they are not used for some time, and then restores them from cloud. Or auto-backup on Android, see parse-community/Parse-SDK-Android#970 (comment). If a user opens the app again after 2 months, maybe it gets restored and that causes some issues, hence you see more errors after covid? |
@dplewis not sure it was addressed to me, but if so yes for sure @mtrezza We have seen the same on test devices where we know for sure this iOS setting is not activated... So I'm guessing it's not linked. BTW we also know that we have an issue each time a user restore its phone as Parse always fails to restore the currentUser (we have activated the anonymous account, so it's hard to detect when this occurs). But I think that's an issue with Parse iOS SDK, and it's another subject. |
I guess the first step would be determining whether the issue is server or client side. The error can be thrown in many different places on the server, can you tell from the stack trace where it is thrown? |
I know. A hint is that it seems to occur on both iOS and Android apps, so it seems to be server side. On client side, we only see the 209 Invalid Session Token error, but with AWS X-Ray we were able to see more details, and it seems it's always this trace:
Which is why I supposed it was an issue with wrongly deleted sessions. |
I assume thats this? Lines 104 to 109 in de79b70
|
I think so... |
That really seems like either the session was removed or the token was incorrect. Did you check whether the requests may be malicious, maybe trying to brute force the session token? See #6755 |
We don't see any weird requests, and it also happens with our own devices / sessions. |
Have you set a TTL index on the session collection |
Interesting that you say "all the session tokens". There should ever only be one session object per user per installation. If all session objects of the user of different installations are deleted, that could point to an issue in your custom code. If I understand this correctly, before a new session object is created, all existing sessions objects of that user/installation combination are destroyed: Line 975 in 288e746
|
No TTL index I think, and we have a lots of old session token, so I guess it wouldn't be the case with a TTL index. (It could be nice to have one haha) But the issue of deleted sessions is for all users. |
I added functionality to build a TTL index in #6748 so someone could add that feature easily after merge
I cannot think of a debugging scenario in which a session would be deleted while it is still in use on another device, given that each device has its own installation ID. I also have never experienced that when debugging. Maybe the issue is related to your custom code where you manipulate sessions / installations / users? Could it be that you try to execute some server calls on the client after the user logged out? I think that would cause the same error? |
Agreed. But we don’t manipulate sessions/installations. We use standard logout/login, and the only thing we do is saving the user in the installation. We do have triggers on Users but that’s all.
Do you think we could patch the server code to add some debug logs or hints that could explain anything? |
Definitely, it would be interesting to see which tokens are sent by the clients that are invalid. Now you don't want tokens in your logs, but these are invalid tokens anyway. Then you could log when a token gets deleted, in Parse Server or with even with a mongodb trigger on the DB level. Then you would know:
You may want to log logout / password change / password reset operations as well; I don't know off the top of my head whether these trigger a session delete as well. |
Yes I'll try to add some logs thanks |
Sure, let us know what you found. |
@SebC99 Are there any new insights on this? |
Unfortunately no, we still have the issue, and we can't figure out why. Our logs in our app are not helping as we only see that people are "loosing" their session token at one point, and that those session tokens were valid just before (with an expiration date in 2021). |
Interesting. I will also take a look into logs. For which platforms (SDKs) do you obverse this? |
We use the iOS, Android and JS SDK and we mostly see that on the iOS one, but that's also because most of our users are using iOS |
So it does occur with all 3 SDKs? Can you check that to be sure? For example for Android you'd want to make sure a user does not login with iOS as well and therefore the session is deleted somehow. In other words, if you have users who only use the Android SDK or only the JS SDK, whether they are affected as well. Did you patch the server to get more logs as discussed? |
Really hard to say as it's seems to be random. We have almost no users using both Android and iOS, but we do have lots of users with multiple iOS devices, and some of them are also using the web app on their computer. As far as we can see, we see more of that issue with users with multiple devices. As for the logs, not for now as I don't know what kind of logs to add in parse-server.... We did add logs in the clients app but it didn't help. We could add a beforeDelete hook in the cloud code, but I don't know what to display in the logs that could be helpful. |
Let's analyze a bit more where we observe it and what we observe, so we don't overlook anything.
|
I’ll add those logs yes! Thanks ! |
Just for reference I'm adding #6726 because it is somewhat related. |
@mtrezza we might have found something... |
Now that's interesting.
Is it expected that changing a password causes invalidates all other sessions? I know some services do that (e.g. Google) while others do not (e.g. Instagram). I could see that as a feature, but it would have to be consistent across the SDKs of course. If it's currently inconsistent maybe we can take this as a opportunity to introduce a Parse Server configuration parameter for this, unless there is a best practice we should abide to. |
Well, on one device, when we do a login then just a save, it occurs each time (transforming the session from a login one to a signup one) (I think there’s already a setting in parse server for that: |
BTW, this code (in Auth.js) is weird:
It means each time a new sessionToken is created (because of a save with a password, even the same as before), the |
You are right, Parse Server never stops to amaze. |
Can we close this issue or do you have any further info? |
No more info except it's still happening... |
I'm reluctant to close this, because if it is indeed a bug, it may be an important one that affects user experience. You wrote
Can you still observe this? Could you just debug the iOS app and Parse Server and step through the code to see why this is happening? |
Unfortunately as soon as we compiled a debug version on the device, it stopped on that one. So we're back with the bug happening randomly, with no clue for now |
Not sure if it is related to this issue but I've been experiencing a strange problem with invalid session tokens as well.
But if I do this
|
I am experiencing a similar issue and am uncertain if this is directly related, but does this only occur when directAccess is set to true? I've tracked down missing session tokens in my app (entirely using the JS SDK) to when there is an update of the user record and directAccess is enabled. It triggers a logout call which removes the session token. I can't quite work out how this is called? I've tried putting some logging into the transformUser method of RestWrite.js but that doesn't seem to get fired when direct access is enabled? Disabling direct access prevents the logout from being called and the sessions are not deleting. I've searched the code until my eyeballs bleed, could either of you @SebC99 or @mtrezza point me in the direction for where a logout call might be made after modifying the user object? It definitely seems to occur, by adding some logging into the ParseServerRESTController.js I can see that a POST to logout is called straight after a PUT to /classes/_User. |
@oli107 This is certainly an interesting observation and to my knowledge the only clearly reproducible case so far. Can you reproduce this with a clean local installation of Parse Server? If so, you could debug Parse Server while running into this scenario and find the stack trace that calls |
Haven't had the time to reproduce in a brand new installation yet unfortunately. Not sure if this question
was meant for me but I haven't explicity set directAccess so I guess it should default to false. |
@SebC99 I stumbled upon this comment and it reminded me of this unsolved mystery - maybe related? |
@mtrezza the last comment reminds me of the issue we had with the password being sent again, which leads to the parse-server thinking it's a change of password and thus deleting all sessions |
@SebC99 That's what I was thinking too, sounds remarkably related. Is this still an issue you're investigating? |
the password being sent was an issue on our side, so it has been fixed, but we still have the deleted session issues (just a bit less), and we have not a single clue about it. |
@SebC99 could it have something to do with expiration of 3rd party tokens? Have you observed this only with FB access token for example? Do you have any customization related to the auth adapter or access token / Parse session handling? |
No customization on this, but I think there's room for improvement yes: typically, as parse-server only test the token on login, when the FB token expires, you can have an active Parse user (with a valid session) but with an invalid Facebook token. So if your app uses the FB token to retrieve data (like friends, profile info or anything), Facebook will show an alert (if you use the FB SDK) whereas it's still valid for parse-server. But to answer your question, it's more often with FB access, but it is also happening with email access. |
I am not sure whether/how the parse session validity should be related to the 3rd party token validity. It would be interesting to see what's best practice.
Then I'd still leave the issue open for now. |
I'm closing this due to lack of information for further investigation. |
Issue Description
We do log a big number of INVALID_SESSION_TOKEN errors for our users, appearing without any apparent logic: sessions are not expired, the user hasn't changed the password, sometimes it happens multiple times in the same day, and we can't figure out why.
Is there any way for us to better detect the reason for this?
Are we the only one with this weird behavior?
I know there's multiple places in the code where Sessions are deleted (or session caches) but I can't see why it could explain that.
Any help would be appreciated :)
The text was updated successfully, but these errors were encountered: