Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Error in getting cross-component correlationid? #524

Closed

Description

I have a weird exception on one of my servers. It occurs at the second request after appstart. It crashes the appdomain completely.

System.InvalidOperationException: Invalid non-ASCII or control character in header: 0x000A
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders.ThrowInvalidHeaderCharacter(Char ch)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders.ValidateHeaderCharacters(String headerCharacters)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders.ValidateHeaderCharacters(StringValues headerValues)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameResponseHeaders.SetValueFast(String key, StringValues value)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_Item(String key, StringValues value)
   at Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners.HttpHeadersUtilities.SetHeaderKeyValue(IHeaderDictionary headers, String headerName, String keyName, String keyValue)
   at Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners.HostingDiagnosticListener.SetAppIdInResponseHeader(HttpContext httpContext, RequestTelemetry requestTelemetry)
   at Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners.HostingDiagnosticListener.OnBeginRequest(HttpContext httpContext, Int64 timestamp)
   at Proxy_Method_From_<>f__AnonymousType0`2_To_Void OnBeginRequest(Microsoft.AspNetCore.Http.HttpContext, Int64)(Object , Object , IProxyFactory )
   at Microsoft.Extensions.DiagnosticAdapter.DiagnosticSourceAdapter.Write(String diagnosticName, Object parameters)
   at Microsoft.Extensions.DiagnosticAdapter.DiagnosticSourceAdapter.System.IObserver<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.OnNext(KeyValuePair`2 value)
   at System.Diagnostics.DiagnosticListener.Write(String name, Object value)
   at Microsoft.AspNetCore.Hosting.Internal.HostingApplication.CreateContext(IFeatureCollection contextFeatures)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()

Peeking at the source, I see that the crash accurs at the following line:

HttpHeadersUtilities.SetRequestContextKeyValue(responseHeaders, RequestResponseHeaders.RequestContextTargetKey, correlationId);

Looks like the cross-component correlationId lookup returns something funky. I think the problem might be that the lookup produces some sort of an error string which is used as appId:

CorrelationIdLookupHelper.cs:141

getAppIdTask.ContinueWith((appId) =>
                            {
                                try
                                {
                                    this.GenerateCorrelationIdAndAddToDictionary(instrumentationKey, appId.Result);
                                }
                                catch (Exception ex)
                                {
                                    AspNetCoreEventSource.Instance.LogFetchAppIdFailed(ExceptionUtilities.GetExceptionDetailString(ex));
                                }
                                finally
                                {
                                    int currentTaskId;
                                    iKeyTaskIdMapping.TryRemove(iKeyLowered, out currentTaskId);
                                }
                            });

I think CorrelationIdLookupHelper.FetchAppIdFromService should also verify if the response code was a success, before returning a result string (which might be a http error text, such as a proxy auth required error).

(Using version "Microsoft.ApplicationInsights.AspNetCore": "2.1.0")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions