Skip to content

DistributedSession always loads session in CommitAsync even when session is not modified #42009

Closed
@MichalSznajder

Description

@MichalSznajder

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

As part of f99b482 code is DistributedSession.CommitsAsync was modified to check IsAvailable.

public async Task CommitAsync(CancellationToken cancellationToken = default)

IsAvailable always loads session from backing store and loads it in synchronous way.

On the other hand SessionMiddleware always calls DistributedSession.CommitAsync to save session. This means that in 6.0 session is always loaded even if application code did not touch it at all. In case of using Redis as backing store this incurs two Redis calls on each RazorPage rendered.

await feature.Session.CommitAsync();

In the past (5.0) when session was not touched DistributedSession._isModified prevented session data from being loaded when session was not modified.

@pranavkm Could you tell why IsAvailable was moved?

Expected Behavior

Don't loading session data from backing store when session data is not modified by app code.

.NET Version

6.0.300

Metadata

Metadata

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions