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

Thread-safe Item Collections for Concurrent mode #112

Merged
merged 6 commits into from
Mar 21, 2025
Merged

Conversation

StephenMolloy
Copy link
Collaborator

Started with PR #99 from @mellamokb. Decided to fill out the concept to apply to all our async providers that might work in AllowConcurrentRequestsPerSession mode.

Original PR description:

Added new ThreadSafeSessionStateItemCollection to replace built-in Microsoft one. This fixes the race condition in the indexers. Also commented out all serialization since this is intended to only be used with the in-memory session, so serialization is not necessary.

This pull request introduces significant changes to the session state management in the CosmosDBSessionStateProviderAsync and SqlSessionStateProviderAsync classes, focusing on support for concurrent requests and improved serialization. The most important changes include the addition of new helper methods for creating and serializing session state item collections, as well as updates to existing methods to utilize these new helpers.

mellamokb and others added 6 commits August 23, 2023 10:58
Added new ThreadSafeSessionStateItemCollection to replace built-in Microsoft one.  This fixes the race condition in the indexers. Also commented out all serialization since this is intended to only be used with the in-memory session, so serialization is not necessary.
@StephenMolloy StephenMolloy requested a review from Copilot March 21, 2025 00:24
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances session state management by introducing thread-safe item collections and helper methods to support concurrent requests across asynchronous session state providers.

  • Introduces new helper methods for creating, serializing, and deserializing session state item collections.
  • Refactors both CosmosDB and SQL session state providers to use thread-safe and configurable item collections.
  • Updates tests to cover both standard and concurrent session collection scenarios.

Reviewed Changes

Copilot reviewed 7 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/SessionStateModule/StateSerializationUtil.cs Adds serialization utilities handling various data types including object serialization via BinaryFormatter.
src/CosmosDBSessionStateProviderAsync/CosmosDBSessionStateProviderAsync.cs Refactors session store data creation to use a configurable item collection method.
src/SqlSessionStateProviderAsync/SqlSessionStateProviderAsync.cs Consolidates item collection creation and serialization/deserialization logic for concurrent scenarios.
src/SessionStateModule/SessionStateModuleAsync.cs Exposes a configuration flag to control concurrent request handling.
src/SessionStateModule/InProcSessionStateStoreAsync.cs Adjusts session item initialization based on the concurrent requests flag.
test/Microsoft.AspNet.SessionState.SqlSessionStateProviderAsync.Test/SqlSessionStateAsyncProviderTest.cs Extends tests with varied session collection inputs to validate serialization and deserialization logic.
Files not reviewed (3)
  • src/SessionStateModule/Microsoft.AspNet.SessionState.SessionStateModule.csproj: Language not supported
  • src/SessionStateModule/Resources/SR.Designer.cs: Language not supported
  • src/SessionStateModule/Resources/SR.resx: Language not supported
Comments suppressed due to low confidence (2)

test/Microsoft.AspNet.SessionState.SqlSessionStateProviderAsync.Test/SqlSessionStateAsyncProviderTest.cs:232

  • The test data method yields duplicate scenarios for session collection types which may limit the diversity of test cases. Consider diversifying the inputs to better cover all supported configurations.
public static IEnumerable<object[]> SerializeSessionData()

src/SqlSessionStateProviderAsync/SqlSessionStateProviderAsync.cs:175

  • [nitpick] The 'CreateItemCollection' method is introduced in multiple files with similar logic. Consolidating this functionality into a shared utility could reduce code duplication and improve maintainability.
private static ISessionStateItemCollection CreateItemCollection()

@StephenMolloy StephenMolloy merged commit 8620efb into main Mar 21, 2025
1 check passed
@StephenMolloy StephenMolloy deleted the issue-95-branch branch March 21, 2025 00:41
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