Skip to content

Loading session state asynchronously - potential usage problem  #27733

@mstavrev

Description

@mstavrev

There is a potential issue regarding the section:

Load session state asynchronously

Naturally, whoever is implementing such a work-around to asynchronously load the cache prior to any use (get, set) may decide to use the ISession.IsAvailable property to check if the session had been loaded and only when this property is false to perform the async LoadAsync. However, it turns out that the current MS implementation of DistributedSession (which is the one used when you do the AddSession startup call) has an issue with that - see:

https://github.com/aspnet/Session/blob/774079d60d29762ef7c8bba3f0fa06e73cb323f2/src/Microsoft.AspNetCore.Session/DistributedSession.cs#L82

The IsAvailable property is performing unconditional call to the synchronous version of Load. That means, any code that tries to conditionally load the session data asynchronously will basically complete synchronously.

Please, add an underlined comment on the article that the LoadAsync should be called explicitly, without relying on the IsAvailable property, which actually would otherwise break the async implementation intent.

Best Regards
Marin


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

DocsThis issue tracks updating documentationaffected-fewThis issue impacts only small number of customersarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-sessionhelp wantedUp for grabs. We would accept a PR to help resolve this issueseverity-nice-to-haveThis label is used by an internal tool

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions