mgravell / mgravell/TsavoriteCache
Sliding expiration is limited to 3 minutes and 34 seconds
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 41
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
When trying to add FASTERCache to an ASP.NET Core application with Sessions, I ran into the following exception:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.OverflowException: Arithmetic operation resulted in an overflow.
at FASTERCache.DistributedCache.GetExpiryTicks(DistributedCacheEntryOptions options, Int32& sliding) in /_/src/FASTERCache/DistributedCache.cs:line 307
at FASTERCache.DistributedCache.WriteValue(ReadOnlySequence`1 value, Byte[]& lease, DistributedCacheEntryOptions options) in /_/src/FASTERCache/DistributedCache.cs:line 64
at FASTERCache.DistributedCache.WriteAsync(String key, ReadOnlySequence`1 value, DistributedCacheEntryOptions options, CancellationToken token) in /_/src/FASTERCache/DistributedCache.cs:line 373
at Microsoft.AspNetCore.Session.DistributedSession.CommitAsync(CancellationToken cancellationToken)
This is because code the SlidingExpiration is converted to ticks and then to an integer:
Because of this, the max value of SlidingExpiration is 00:03:34.
For my issue, changing the max session to IdleTimeout to 3 minutes fixes this problem:
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(3);
});
However, 3 minutes is quite small for an idle timeout causing FASTERCache being unusable in this case.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/FASTERCache/DistributedCache.cs at GetExpiryTicks around line 307 and the SlidingExpiration conversion referenced near line 441. Reproduce the issue with an ASP.NET Core session IdleTimeout above three minutes, then verify that a longer sliding expiration no longer causes an arithmetic overflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100