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

Improved re-entrancy Scope Lock for Session Value Layout Render #850

Merged
merged 18 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Shared/Internal/RendererReEntrantManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ internal RendererReEntrantManager(HttpContextBase context)
{
_httpContext = context;
_obtainedLock = false;
TryGetLock();
}

private readonly HttpContextBase _httpContext;

internal bool IsLockAcquired => _obtainedLock;

#if NET35
private static readonly object ReEntrantLock = new object();

Expand Down Expand Up @@ -68,19 +71,17 @@ private void Unlock()
private bool _obtainedLock;
snakefoot marked this conversation as resolved.
Show resolved Hide resolved


internal bool TryGetLock()
private void TryGetLock()
{
// If already locked, return false
if (IsLocked())
{
return false;
return;
}
// Get the lock
Lock();
// Mark that we locked it, not another instance locked it
_obtainedLock = true;
// Return to the caller that we locked it
return true;
}

private void DisposalImpl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)

using (var reEntry = new RendererReEntrantManager(context))
{
if (!reEntry.TryGetLock())
if (!reEntry.IsLockAcquired)
{
InternalLogger.Error(
snakefoot marked this conversation as resolved.
Show resolved Hide resolved
$"Reentrant log event detected. Logging when inside the scope of another log event can cause a StackOverflowException. LogEventInfo.Message:{logEvent.Message}");
Expand Down