Skip to content

Commit f99b482

Browse files
committed
Fixup
1 parent 078f9cf commit f99b482

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Middleware/Session/src/DistributedSession.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ public async Task LoadAsync(CancellationToken cancellationToken = default)
267267
/// <inheritdoc />
268268
public async Task CommitAsync(CancellationToken cancellationToken = default)
269269
{
270+
if (!IsAvailable)
271+
{
272+
_logger.SessionNotAvailable();
273+
return;
274+
}
275+
270276
using (var timeout = new CancellationTokenSource(_ioTimeout))
271277
{
272278
var cts = CancellationTokenSource.CreateLinkedTokenSource(timeout.Token, cancellationToken);
@@ -350,11 +356,6 @@ private void Serialize(Stream output)
350356
{
351357
output.WriteByte(SerializationRevision);
352358
SerializeNumAs3Bytes(output, _store.Count);
353-
if (!IsAvailable)
354-
{
355-
throw new InvalidOperationException("Cannot commit session data since initial load failed.");
356-
}
357-
358359
output.Write(IdBytes, 0, IdByteCount);
359360

360361
foreach (var entry in _store)

src/Middleware/Session/src/LoggingExtensions.cs

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal static class LoggingExtensions
1919
private static Action<ILogger, Exception?> _sessionCommitCanceled;
2020
private static Action<ILogger, Exception?> _sessionRefreshTimeout;
2121
private static Action<ILogger, Exception?> _sessionRefreshCanceled;
22+
private static Action<ILogger, Exception?> _sessionNotAvailable;
2223

2324
static LoggingExtensions()
2425
{
@@ -70,6 +71,10 @@ static LoggingExtensions()
7071
eventId: new EventId(12, "SessionRefreshCanceled"),
7172
logLevel: LogLevel.Information,
7273
formatString: "Refreshing the session was canceled.");
74+
_sessionNotAvailable = LoggerMessage.Define(
75+
eventId: new EventId(13, "SessionCommitNotAvailable"),
76+
logLevel: LogLevel.Information,
77+
formatString: "Session cannot be committed since it is unavailable.");
7378
}
7479

7580
public static void ErrorClosingTheSession(this ILogger logger, Exception exception)
@@ -131,5 +136,7 @@ public static void SessionRefreshCanceled(this ILogger logger)
131136
{
132137
_sessionRefreshCanceled(logger, null);
133138
}
139+
140+
public static void SessionNotAvailable(this ILogger logger) => _sessionNotAvailable(logger, null);
134141
}
135142
}

0 commit comments

Comments
 (0)