Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Log messages from HostingEngine are sometimes null #454

Closed
@kichalla

Description

@kichalla

Example line of code causing the issue: https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNet.Hosting/Internal/HostingLoggerExtensions.cs#L140

Suggestion (from @rynowak ): Change it to a lazy initialize pattern ex:

If (_cached == null)
{
  _cached = …;
}

Suggestion (from @loudejard): Add the missing piece

public override string ToString() => 
_cachedToString ?? Interlocked.CompareExchange(
                ref _cachedToString,
                $"Request starting {_httpContext.Request.Protocol} {_httpContext.Request.Method} {_httpContext.Request.Scheme}://{_httpContext.Request.Host}{_httpContext.Request.PathBase}{_httpContext.Request.Path}{_httpContext.Request.QueryString} {_httpContext.Request.ContentType} {_httpContext.Request.ContentLength}",
                null) ?? _cachedToString;

The CompareExchange will return null when it's successful, but we want it to return the new value (now stored in _cachedToString).

@loudej @lodejard

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions