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

throw an exception on id.get if session is not available #57902

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iamkrillin
Copy link

@iamkrillin iamkrillin commented Sep 16, 2024

Throw exception on id.get

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Description

Throw an exception in DistributedSession.Id.Get if the session is not available

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware label Sep 16, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 16, 2024
Copy link
Contributor

Thanks for your PR, @iamkrillin. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@amcasey
Copy link
Member

amcasey commented Sep 17, 2024

It looks like the unavailability of a session is already signalled by an empty Id. Is that not sufficient?

@iamkrillin
Copy link
Author

The problem I was running into was two fold:

  1. The documentation says the Id returned is unique, which strictly speaking, if there is a possibility for it to return "" is not always true, but the bigger problem was..
  2. When using sqlserverdistributedcache, if there is a problem with the setup (server not available, table missing, etc). The error gets eaten then logged to the console (which is not ideal when using IIS hosting)

These two things combined lead to a scenario where things looked to be working, but were not working. When I was working on this PR I though it was better to throw an exception since that would make it very clear that things were not working, but returning null would also work

Either of these would be preferable to eating a error, then returning a value IMO

@amcasey
Copy link
Member

amcasey commented Sep 17, 2024

I'm not actually familiar with this type, but the current behavior certainly appears to be intentional. If we were going to move to a model where it throws, wouldn't it make more sense to just add a throw in Loads catch block?

Similarly, it would have been easy to give each failed session its own guid, so I assume they were grouped together with the id "" on purpose. (Whether that purpose is valid, I have no idea, though it's a common enough pattern.)

@iamkrillin
Copy link
Author

That's a fair enough point, I did consider adding a throw into the catch in Load, I ultimately decided against it since Load is called in many places and I wanted my change to be as small as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants