ServiceStack logging request body under load issue? - servicestack

Switched on request logging of body and in development it works fine. Testing now under load and getting error in my log4net logs.
ERROR 17-10-2019 14:34:44 ServiceStack.ServiceStackHost [50] - ServiceBase<TRequest>::Service Exception System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'The stream with Id eacfc65d-dcfc-45dd-906b-ddbdb9dd025b and Tag is disposed.'.
at ServiceStack.Text.RecyclableMemoryStream.CheckDisposed() in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\RecyclableMemoryStream.cs:line 1393
at ServiceStack.Text.RecyclableMemoryStream.set_Position(Int64 value) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\RecyclableMemoryStream.cs:line 1017
at ServiceStack.StreamExtensions.ReadToEnd(MemoryStream ms, Encoding encoding) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\StreamExtensions.cs:line 363
at ServiceStack.StreamExtensions.ReadToEnd(Stream stream, Encoding encoding) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\StreamExtensions.cs:line 442
at ServiceStack.Host.NetCore.NetCoreRequest.GetRawBody() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line 207
at RvRequestLogger.DbRequestLogger.CreateEntry(IRequest request, Object requestDto, Object response, TimeSpan requestDuration, Type requestType) in /opt/atlassian/pipelines/agent/build/RvRequestLogger/DbRequestLogger.cs:line 129
at RvRequestLogger.DbRequestLogger.Log(IRequest request, Object requestDto, Object response, TimeSpan elapsed) in /opt/atlassian/pipelines/agent/build/RvRequestLogger/DbRequestLogger.cs:line 47
at ServiceStack.HttpExtensions.EndHttpHandlerRequestAsync(IResponse httpRes, Boolean skipHeaders, Boolean skipClose, Func`2 afterHeaders) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\HttpExtensions.cs:line 121
at ServiceStack.HttpResponseExtensionsInternal.WriteToResponse(IResponse response, Object result, StreamSerializerDelegateAsync defaultAction, IRequest request, Byte[] bodyPrefix, Byte[] bodySuffix, CancellationToken token) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\HttpResponseExtensionsInternal.cs:line 364
at ServiceStack.Validation.ValidationFilters.RequestFilterAsync(IRequest req, IResponse res, Object requestDto, Boolean treatInfoAndWarningsAsErrors) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Validation\ValidationFilters.cs:line 65
Now my DbRequestLogger line 129 is doing this, GetRawBody;
if (EnableRequestBodyTracking)
{
#if NETSTANDARD2_0
// https://forums.servicestack.net/t/unexpected-end-of-stream-when-uploading-to-aspnet-core/6478/6
if (!request.ContentType.MatchesContentType(MimeTypes.MultiPartFormData))
{
entry.RequestBody = request.GetRawBody();
}
#else
entry.RequestBody = request.GetRawBody();
#endif
}
This might be related to this post https://forums.servicestack.net/t/unexpected-end-of-stream-when-uploading-to-aspnet-core/6478/8
Any ideas? Seems the request has passed us by at this point.

Related

Azure Managed Identity Token couldn't produce from local

This is a continuation of the ticket Restrict Access with Azure Managed Identity in .NET Core Web API where I configured a .NET Core Web API to secured with user-assigned Azurre Managed Identity. This Web API has been deployed as https://epd-api.azurewebsites.net.
Now I have a locally running/debugging .NET Core WebApp trying to access the managed identity token for above azue deployed Web API as below.
string userAssignedClientId = "<<managed-identity clientid>>";
var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { ManagedIdentityClientId=userAssignedClientId });
var accessToken = await credential.GetTokenAsync(new TokenRequestContext(new[] { "https://epd-api.azurewebsites.net/.default" }));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token);
It's breaking at line 'credential.GetTokenAsync()' with below exceptionn message.
AuthenticationFailedException: Azure CLI authentication failed due to
an unknown error. See the troubleshooting guide for more information.
https://aka.ms/azsdk/net/identity/azclicredential/troubleshoot ERROR:
The command failed with an unexpected error. Here is the traceback:
ERROR: Get Token request returned http error: 400 and server response:
{"error":"invalid_resource","error_description":"AADSTS500011: The
resource principal named https://epd-api.azurewebsites.net was not
found in the tenant named DXC Production. This can happen if the
application has not been installed by the administrator of the tenant
or consented to by any user in the tenant. You might have sent your
authentication request to the wrong tenant.\r\nTrace ID:
b537e8c2-c1a8-44ff-a363-d162cd15e101\r\nCorrelation ID:
507df083-138c-4848-b446-40631732a181\r\nTimestamp: 2022-09-13
06:52:22Z","error_codes":[500011],"timestamp":"2022-09-13
06:52:22Z","trace_id":"b537e8c2-c1a8-44ff-a363-d162cd15e101","correlation_id":"507df083-138c-4848-b446-40631732a181","error_uri":"https://login.microsoftonline.com/error?code=500011"}
Traceback (most recent call last):
Once I deployed my Web APP in Azure, the error message is different as below.
Connection ID "15636497907840976997", Request ID
"80000866-0000-d900-b63f-84710c7967bb": An unhandled exception was
thrown by the application.
Exception: Azure.Identity.AuthenticationFailedException:
ManagedIdentityCredential authentication failed: Service request
failed. Status: 500 (Internal Server Error)
Content:
Headers: Date: Tue, 13 Sep 2022 07:39:11 GMT Server: Kestrel
Transfer-Encoding: chunked X-CORRELATION-ID: REDACTED Content-Type:
application/json; charset=utf-8
See the troubleshooting guide for more information.
https://aka.ms/azsdk/net/identity/managedidentitycredential/troubleshoot
---> Azure.RequestFailedException: Service request failed. Status: 500 (Internal Server Error)
Content:
Headers: Date: Tue, 13 Sep 2022 07:39:11 GMT Server: Kestrel
Transfer-Encoding: chunked X-CORRELATION-ID: REDACTED Content-Type:
application/json; charset=utf-8
at Azure.Identity.ManagedIdentitySource.HandleResponseAsync(Boolean
async, TokenRequestContext context, Response response,
CancellationToken cancellationToken) at
Azure.Identity.ManagedIdentitySource.AuthenticateAsync(Boolean async,
TokenRequestContext context, CancellationToken cancellationToken)
at Azure.Identity.ManagedIdentityClient.AuthenticateAsync(Boolean
async, TokenRequestContext context, CancellationToken
cancellationToken) at
Azure.Identity.ManagedIdentityCredential.GetTokenImplAsync(Boolean
async, TokenRequestContext requestContext, CancellationToken
cancellationToken) --- End of inner exception stack trace --- at
Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception
ex, String additionalMessage) at
Azure.Identity.ManagedIdentityCredential.GetTokenImplAsync(Boolean
async, TokenRequestContext requestContext, CancellationToken
cancellationToken) at
Azure.Identity.ManagedIdentityCredential.GetTokenAsync(TokenRequestContext
requestContext, CancellationToken cancellationToken) at
Azure.Identity.DefaultAzureCredential.GetTokenFromSourcesAsync(TokenCredential[]
sources, TokenRequestContext requestContext, Boolean async,
CancellationToken cancellationToken) at
Azure.Identity.DefaultAzureCredential.GetTokenImplAsync(Boolean async,
TokenRequestContext requestContext, CancellationToken
cancellationToken) at
Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception
ex, String additionalMessage) at
Azure.Identity.DefaultAzureCredential.GetTokenImplAsync(Boolean async,
TokenRequestContext requestContext, CancellationToken
cancellationToken) at
Azure.Identity.DefaultAzureCredential.GetTokenAsync(TokenRequestContext
requestContext, CancellationToken cancellationToken) at
ManagedIdentityWeb.Pages.IndexModel.OnGetAsync() in
C:\Users\jmathews4\Source\Repos\ManagedIdentityAPI\ManagedIdentityWeb\Pages\Index.cshtml.cs:line
36 at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.NonGenericTaskHandlerMethod.Execute(Object
receiver, Object[] arguments) at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext
context) at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State&
next, Scope& scope, Object& state, Boolean& isCompleted)
at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker
invoker, Task lastTask, State next, Scope scope, Object state, Boolean
isCompleted) at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed
context) at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State&
next, Scope& scope, Object& state, Boolean& isCompleted)
at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker
invoker, Task lastTask, State next, Scope scope, Object state, Boolean
isCompleted) at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker
invoker, Task task, IDisposable scope) at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker
invoker, Task task, IDisposable scope) at
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint
endpoint, Task requestTask, ILogger logger) at
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
Any clue here for troubleshoot?
It's trying to use the AZ CLI there and its refresh token has expired. Run az login again in the command line and try again.

IronPDF System.Exception Error while generating PDF from Url in Azure function

I have an Azure (durable) function that is using the new Runtime Version 3 which is supposed to generate a PDF using IronPDF from a URL. The function keeps failing and the only error that gets logged to Insights is something like this:
Exception: Exception while executing function: A_GetPdfDataFromUrl
Type: Microsoft.Azure.WebJobs.Host.FunctionInvocationException
Stack Trace
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: A_GetPdfDataFromUrl
---> System.Exception: Error while generating PDF from 'https://www.myurl.com'
at .(String , CefRenderSettings , CefBrowserSettings )
at .RenderPdfDocumentFromUri(ChromePdfRenderOptions Options, ChromeHttpLoginCredentials Login, Uri url)
at IronPdf.Rendering.Abstractions.PdfRenderProxy'2.RenderUrlAsPdf(Uri Url)
at IronPdf.Rendering.Abstractions.PdfRenderProxy'2.RenderUrlAsPdf(String UrlOrPath)
at IronPdf.Rendering.Abstractions.PdfRenderProxy'2.<>c__DisplayClass19_0.b__0()
at System.Threading.Tasks.Task'1.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
at MyFuncs.PdfFunc.GetPdfDataFromUrl(String url) in D:\a\1\s\Funcs\PdfFunc.cs:line 155
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker'2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 572
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 518
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 296
Unfortunately, IronPDF logs dont get generated in Azure due to a bug in their current version which they said will be fixed in the next release. So until then I'm unable to figure out why this simple code is failing in Azure.
[FunctionName("A_GetPdfDataFromUrl")]
public async Task<byte[]> GetPdfDataFromUrl([ActivityTrigger] string url)
{
IronPdf.License.LicenseKey = "";
IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
ChromePdfRenderer chromePdfRenderer = new ChromePdfRenderer();
var trackReportPdf = chromePdfRenderer.RenderUrlAsPdf(url);
return trackReportPdf.BinaryData;
}
Thank you darren. Posting your suggestions as an answer to help other community members.
The logs will be generated in Azure where all the logs will be stored in a container called $logs. The container $logs is automatically generated when the storage account is created.
All logs are stored in block blobs in a container named $logs.
This is automatically created when Storage Analytics is enabled for a storage account.
The $logs container is located in the blob namespace of the storage account
To answer your question Raihan-Iqbal
Do you mean the storage account that is assigned to the azure function
Yes the storage account that creates when we create Azure Function or it may be any of the storage account the $logs container will be generated automatically.
For further details see Iron Log Files.

Request body too large

When I try to upload a 80mb file from postman to my local endpoint running in Visual Studio 2019 on IISExpress I get the following error:
The request filtering module is configured to deny a request that exceeds the request content length.
So I added this to applicationhost.config for the project:
<system.web>
<httpRuntime maxRequestLength="1050000" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824"/>
</requestFiltering>
</security>
This stop the error coming when I make the API request but now I just get a ServiceStack generated "snapshot" page telling me how long request took and the date but my actual endpoint is never hit.
Inside my logs I can see ServiceStack throwing this exception:
2020-07-20 01:57:56.0497||ERROR|ServiceStackHost|Request body too
large. Microsoft.AspNetCore.Server.IIS.BadHttpRequestException:
Request body too large. at
Microsoft.AspNetCore.Server.IIS.BadHttpRequestException.Throw(RequestRejectionReason
reason) at
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.InitializeRequestIO()
at
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadAsync(Memory1 memory, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.ReadAsyncInternal(Memory1
buffer, CancellationToken cancellationToken) at
Microsoft.AspNetCore.WebUtilities.BufferedReadStream.EnsureBufferedAsync(Int32
minCount, CancellationToken cancellationToken) at
Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[]
buffer, Int32 offset, Int32 count, CancellationToken
cancellationToken) at
Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream
stream, ArrayPool1 bytePool, Nullable1 limit, CancellationToken
cancellationToken) at
Microsoft.AspNetCore.WebUtilities.MultipartReader.ReadNextSectionAsync(CancellationToken
cancellationToken) at
Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken
cancellationToken) at
Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm() at
Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form() at
ServiceStack.Host.NetCore.NetCoreRequest.get_FormData() in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line
167 at
ServiceStack.HttpRequestExtensions.GetFlattenedRequestParams(IRequest
request) in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\HttpRequestExtensions.cs:line
555 at ServiceStack.Host.RestHandler.CreateRequestAsync(IRequest
httpReq, IRestPath restPath) in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line
132 at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest
req, IResponse httpRes, String operationName) in
C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line
89|url: |action:
So the Body length still needs to be set somewhere but everywhere I look points back to the config I have already used.
Is there additional setting required or is this a ServiceStack issue?
I was missing this option in startup:
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue;
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = int.MaxValue; // if don't set default value is: 30 MB
});

Request not supported: RemoveMember/AddMember/SetStateDynamicEntity

I was analyzing the trace logs from production server for my MS CRM 2011 deployment with UR18 and observed that there are multiple entries for the below exceptions -
Message: Request not supported: RemoveMember, ErrorCode: -2147220715
Message: Request not supported: AddMember, ErrorCode: -2147220715
Message: Request not supported: SetStateDynamicEntity, ErrorCode: -2147220715
The trace log for AddMember is something like below.
I did not get any clue from this log. I even searched for the supported messages for MS CRM 2011 which shows that these messages are supported.
Did anybody face such issue or have any clue around this? All inputs are appreciated. :)
at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) ilOffset = 0x86
at QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() ilOffset = 0x23
at ThreadPoolWorkQueue.Dispatch() ilOffset = 0x81
at _ThreadPoolWaitCallback.PerformWaitCallback() ilOffset = 0x51
Crm Exception: Message: Request not supported: AddMember, ErrorCode: -2147220715

ServiceStack: SerializationException

I am testing the api created using ServiceStack using SoapUI and when I try to send the required DataMember thru headers, the api returns the correct values. When I try to send the required DataMember thru Body, I am getting the below error... Please help
Request sent through the body
<GetProductDetailsReq>
<AToken>ck0b0YYBPkrnVF/j6e16DUPzxLX2SMCXewoR4T</AToken>
</GetProductDetailsReq>
POST http://localhost/ServiceStackAPI/GetProductDetails HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/xml
Accept: application/xml
Content-Length: 777
Host: localhost
Proxy-Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Response Status
Error Code
SerializationException Message
Could not deserialize 'application/xml' request using ServiceModel.DTO.GetProductDetailsReq' Error:
System.Runtime.Serialization.SerializationException: Error in line 1
position 66. Expecting element 'GetProductDetailsReq' from namespace
''.. Encountered 'Element' with name 'GetProductDetailsReq', namespace
'http://schemas.servicestack.net/types'. at
System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator
xmlReader, Boolean verifyObjectName, DataContractResolver
dataContractResolver) at
System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator
reader, Boolean verifyObjectName, DataContractResolver
dataContractResolver) at
System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader
reader) at
System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream
stream) at ServiceStack.Text.XmlSerializer.DeserializeFromStream(Type
type, Stream stream) at
ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest
httpReq, Type requestType, String contentType) Stack Trace
at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest
httpReq, Type requestType, String contentType) at
ServiceStack.WebHost.Endpoints.RestHandler.GetRequest(IHttpRequest
httpReq, IRestPath restPath) at
ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest
httpReq, IHttpResponse httpRes, String operationName)
Check the SOAP Limitations to ensure you're creating Services that can be sent in SOAP, i.e. If the Request DTO is called GetProductDetails then it must return a Response DTO called GetProductDetailsResponse. Also you need to ensure your DTO's have [DataContract] on all types and [DataMember] on all public properties and that your DTO's are in a single namespace.
The other issue with this request is that you're using the SOAP requests to wrong endpoint address. i.e. The SOAP endpoint is either /soap11 or /soap12. In the above example it's attempting to send it to the /GetProductDetails custom HTTP route, when for SOAP it needs to be either /soap11 or soap12.
If you did just want to just send XML over HTTP then you should just send the raw XML payload which you can find out what it looks like by serializing the Request DTO, e.g:
string requestXml = new GetProductDetails { ... }.ToXml();
Which you can easily send with HTTP Utils:
var responseXml = "http://localhost/ServiceStackAPI/GetProductDetails"
.PostXmlToUrl(xmlRequest);
var responseDto = responseXml.FromXml<GetProductDetailsResponse>();
Assuming you have a [Route("/GetProductDetails")] defined on the GetProductDetails Request DTO.

Resources