You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, if the string "test" is written into the MemoryStream object, the length of the buffer returned from GetBuffer is 256, not 4, with 252 bytes unused. To obtain only the data in the buffer, use the ToArray method; however, ToArray creates a copy of the data in memory.
So the size of the memory becomes 256 * 2^N (256, 512, 1024, 2048, 4096 ...) if the actual data size is over 256 * 2^(N-1).
Therefore the size of the session item is bigger than the actual data size of the one.
The text was updated successfully, but these errors were encountered:
Title
The size of the session item is bigger than the actual data size of the one when using CosmosDBSessionStateProviderAsync.
Functional impact
The user need to increase the RU of the Cosmos DB Provider more than enough.
Minimal repro steps
Expected result
The size of the session data is dozens of bytes at most.
Actual result
The size of the session data is hundreds of bytes.
How to fix
Use the MemoryStream.ToAttay() instead of MemoryStream.GetBuffer at the following line.
https://github.com/aspnet/AspNetSessionState/blob/master/src/CosmosDBSessionStateProviderAsync/CosmosDBSessionStateProviderAsync.cs#L1148
https://github.com/aspnet/AspNetSessionState/blob/master/src/CosmosDBSessionStateProviderAsync/CosmosDBSessionStateProviderAsync.cs#L1161
Further technical details
The CosmosDBSessionStateProviderAsync get the session item which the application set by calling MemoryStream.GetBuffer().
But the MemoryStream.GetBuffer() return the memory which includes the unused one.
MemoryStream.GetBuffer Method
So the size of the memory becomes 256 * 2^N (256, 512, 1024, 2048, 4096 ...) if the actual data size is over 256 * 2^(N-1).
Therefore the size of the session item is bigger than the actual data size of the one.
The text was updated successfully, but these errors were encountered: