Starts in:
2 DAYS
9 HRS
42 MIN
31 SEC
Starts in:
2 D
9 H
42 M
31 S
Open Closed

Sentry intercepts image post from app #7363


User avatar
0
rivz created
  • ABP Framework version: v8.1.1

  • UI Type: Blazor Server

  • Database System: EF Core (PostgreSQL)

  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

  • Exception message and full stack trace:

  • [10:20:20 ERR] Error saving image for non-conformance: c5e449f6-6237-447e-b2d4-baf042fd903e System.InvalidOperationException: The inner stream position has changed unexpectedly. at Microsoft.AspNetCore.Http.ReferenceReadStream.VerifyPosition() at Microsoft.AspNetCore.Http.ReferenceReadStream.ReadAsync(Memory1 buffer, CancellationToken cancellationToken) at System.IO.Stream.<CopyToAsync>g__Core|27_0(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken) at Devication.InspectleFood.HygieneReports.NonConformanceAppService.CloneStreamAsync(Stream originalStream) in /app/src/Devication.InspectleFood.Application/HygieneReports/NonConformanceAppService.cs:line 732 at Devication.InspectleFood.HygieneReports.NonConformanceAppService.ResetAndCloneStream(IRemoteStreamContent picture) in /app/src/Devication.InspectleFood.Application/HygieneReports/NonConformanceAppService.cs:line 744 at Devication.InspectleFood.HygieneReports.NonConformanceAppService.SaveImageAsync(IRemoteStreamContent picture, Guid nonConformanceId, String imageName) in /app/src/Devication.InspectleFood.Application/HygieneReports/NonConformanceAppService.cs:line 751 at Devication.InspectleFood.HygieneReports.NonConformanceAppService.CreateAsync(CreateNonConformanceDto input) in /app/src/Devication.InspectleFood.Application/HygieneReports/NonConformanceAppService.cs:line 698 at lambda_method2189(Closure, Object) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) [10:20:20 ERR] ---------- RemoteServiceErrorInfo ---------- { "code": null, "message": "An internal error occurred during your request!", "details": null, "data": {}, "validationErrors": null } [10:20:20 ERR] The inner stream position has changed unexpectedly. System.InvalidOperationException: The inner stream position has changed unexpectedly. at Microsoft.AspNetCore.Http.ReferenceReadStream.VerifyPosition() at Microsoft.AspNetCore.Http.ReferenceReadStream.ReadAsync(Memory1 buffer, CancellationToken cancellationToken) at System.IO.Stream.<CopyToAsync>g__Core|27_0(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken) at Devication.InspectleFood.HygieneReports.NonConformanceAppService.CloneStreamAsync(Stream originalStream) in /app/src/Devication.InspectleFood.Application/HygieneReports/NonConformanceAppService.cs:line 732 at Devication.InspectleFood.HygieneReports.NonConformanceAppService.ResetAndCloneStream(IRemoteStreamContent picture) in /app/src/Devication.InspectleFood.Application/HygieneReports/NonConformanceAppService.cs:line 744 at Devication.InspectleFood.HygieneReports.NonConformanceAppService.SaveImageAsync(IRemoteStreamContent picture, Guid nonConformanceId, String imageName) in /app/src/Devication.InspectleFood.Application/HygieneReports/NonConformanceAppService.cs:line 751 at Devication.InspectleFood.HygieneReports.NonConformanceAppService.CreateAsync(CreateNonConformanceDto input) in /app/src/Devication.InspectleFood.Application/HygieneReports/NonConformanceAppService.cs:line 698 at lambda_method2189(Closure, Object) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

  • Steps to reproduce the issue: This only happens when sentry is enabled.

Long story short, when posting 1 picture from app to web, everything works fine and correctly. When trying to send 2 or more images, sentry intercepts it and i get this error on host.

When i disable sentry from program.cs, i can send again multiple images as one post.

e// this is where it happens

private static async Task<Stream> CloneStreamAsync(Stream originalStream)
    {
        if (!originalStream.CanRead)
            throw new InvalidOperationException("Original stream cannot be read.");

        MemoryStream clonedStream = new MemoryStream();
        await originalStream.CopyToAsync(clonedStream);
        clonedStream.Position = 0; 
        return clonedStream;
    }

    private async Task<Stream> ResetAndCloneStream(IRemoteStreamContent picture)
    {
        Stream originalStream = picture.GetStream();
        if (originalStream.Position != 0 && originalStream.CanSeek)
        {
            originalStream.Position = 0;
        }
        return await CloneStreamAsync(originalStream);
    }

e// appsettings for sentry

and settings in appsettings :

"Sentry": {
"Dsn": "mydsn",
"SendDefaultPii": true,
"Environment": "Testing",
"MaxRequestBodySize": "Medium",
"MinimumBreadcrumbLevel": "Error",
"MinimumEventLevel": "Error",
"AttachStackTrace": true,
"Debug": false,
"DiagnosticLevel": "Error"
},

2 Answer(s)
  • User Avatar
    0
    rivz created

    I moved the sentry initialization to httphostmodule instead of program.cs and it fixed my issues

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    👍

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06