-
Notifications
You must be signed in to change notification settings - Fork 10.4k
throw an exception on id.get if session is not available #57902
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
Conversation
It looks like the unavailability of a session is already signalled by an empty |
The problem I was running into was two fold:
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 |
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 Similarly, it would have been easy to give each failed session its own guid, so I assume they were grouped together with the id |
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. |
I was hoping an expert would chime in, but I'm not sure there is one for this type. 😆 Barring that, I think I'd prefer to just set it to If you need more explicit error behavior in your app, do you have the option of either checking |
I changed my application to check IsAvailable before opening this pull request, but figured if this behavior impacted me, perhaps it is impacting others. My Application was checking for null before as an error condition so that makes me think at some point in the past perhaps this API returned null in that scenario. My application has been around since .net 3 and is being updated to .net core so it may have been long ago. |
Thanks for taking time to contribute! 😄
It certainly seems possible that the sentinel used to be In my personal opinion, the best way forward would be to update the doc comments to explain that |
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.
Thanks for your patience.
It looks like the conversation with @amcasey landed on potentially documenting the current behavior, instead of adding this check. However, I can see the value of being explicit and given where we are in the release I wonder if it's safe to take this change. So, no objection from me, but someone who is more familiar with the codebase should share their opinion too.
if(IsAvailable == false) | ||
{ | ||
throw new InvalidOperationException("Session not currently available"); | ||
} |
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.
The IsAvailable getter already calls Load()
internally.
If the plan is to leave this check in place, let's remove the Load()
from the line above.
@JamesNK are you by any chance familiar with this code? |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
No, never used it. IMO, I don't think we should change the behavior of the property. We could break people who depend on the current behavior. If we did change the current behavior, then I think an option would be required to revert it if needed. It starts to become a lot of work for not a huge benefit. And, I'm not sure we fully understand why this choice was made in the first place, which makes me hesitant to change it. Instead of this change, I think we should update the documentation to say an |
Thanks @JamesNK.
@iamkrillin would you like to update your PR to do this instead? |
Actually, I'm going to close this for now. @iamkrillin feel free to reopen if you'd like to repurpose this for the documentation change. |
Throw exception on id.get
Summary of the changes (Less than 80 chars)
Description
Throw an exception in DistributedSession.Id.Get if the session is not available