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

Unset client cookies on session destroy #4

Merged
merged 2 commits into from
Jul 25, 2022

Conversation

Ptrskay3
Copy link
Contributor

@Ptrskay3 Ptrskay3 commented Jul 25, 2022

I think it's reasonable to unset cookies at client side whenever the session is destroyed. (At least actix-sessions does this.)

Also, in my opinion it's a much nicer experience to avoid panics, because that causes the response to hang and never arrive. Instead, on storage failure we should send back a 500 INTERNAL_SERVER_ERROR. Also added tracing errors to appropriate places.

Let me know what do you think about these changes.

Other improvements: avoid panic on session storage failure, add tracing to error cases
HeaderValue::from_str(&cookie.to_string()).unwrap(),
);
}
Ok(None) => {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to handle this branch. I suppose due to our setup, this basically never happens.

Copy link
Owner

Choose a reason for hiding this comment

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

I wonder we could reach this branch if we were to clear the storage (perhaps manually, as an example) while clients still hold cookies. If that's a valid case, would it make sense to send the removal cookie here too?

Copy link
Contributor Author

@Ptrskay3 Ptrskay3 Jul 25, 2022

Choose a reason for hiding this comment

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

I've looked into this a little more thoroughly:
Any reasonable session store implementation should call into_cookie_value on async_session::Session. The only way for into_cookie_value to return None is when you explicitly call clone on the session. However, I can imagine some degenerate async_session implementation that breaks this somehow. I don't believe that we should send a removal cookie here.

@maxcountryman
Copy link
Owner

This looks great! Thank you for putting it together. I have one question about the branch you mentioned but I'm happy to merge this as-is.

@maxcountryman maxcountryman merged commit 13f1625 into maxcountryman:main Jul 25, 2022
@maxcountryman
Copy link
Owner

Version 0.2.0 is now available and includes these changes.

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

Successfully merging this pull request may close these issues.

2 participants