dotnet / dotnet-monitor

This repository contains the source code for .NET Monitor - a tool that allows you to gather diagnostic data from running applications using HTTP endpoints
MIT License
635 stars 110 forks source link

Internal Error During Dump File Capture: System.IO.FileNotFoundException for Temp Directory File #7244

Open MKasaei00 opened 2 weeks ago

MKasaei00 commented 2 weeks ago

Description

When I want to capture dump file.

Configuration

I have this docker compose

services:
  star_dia:
    image: my image url
    container_name: container name
    hostname: dia
    ports:
      - 58088:58088
    volumes:
      - diagnostics:/home/star/:Z
    command: sh -c "dotnet MigrationFramework.dll AutoMigration && dotnet MSSE.DIA.dll"
    pull_policy: always
    environment:
      - DOTNET_DiagnosticPorts=/home/star/dotnet-monitor.sock,suspend
    restart: unless-stopped
    depends_on:
      star_am:
        condition: service_started
    networks:
      - star_network

  dotnet-monitor:
    image: mcr.microsoft.com/dotnet/monitor:8
    container_name: dotnet_monitor
    user: 5:5
    environment:
      - DOTNETMONITOR_Authentication__MonitorApiKey__Subject=my subject
      - DOTNETMONITOR_Authentication__MonitorApiKey__PublicKey=my public key
      - DOTNETMONITOR_Urls=http://+:52323
      - DOTNETMONITOR_DiagnosticPort__ConnectionMode=Listen
      - DOTNETMONITOR_Storage__DefaultSharedPath=/diagnostics
      - DOTNETMONITOR_Storage__DumpTempFolder=/tmp
    ports:
      - 52323:52323
    volumes:
      - diagnostics:/diagnostics
    restart: no
    networks:
      - star_network

When I send this request GET http://localhost:52323/dump?type=Full Accept: application/json Authorization: Bearer mytoken

the file is created in the tmp directory of the container but shows an internal error in the response of http request

2024-08-31 13:55:09 {"Timestamp":"2024-08-31T10:25:09.1452448Z","EventId":13,"LogLevel":"Error","Category":"Microsoft.AspNetCore.Server.Kestrel","Message":"Connection id \u00220HN69KRQHJ5GA\u0022, Request id \u00220HN69KRQHJ5GA:00000001\u0022: An unhandled exception was thrown by the application.","Exception":"System.IO.FileNotFoundException: Could not find file \u0027/tmp/c521a9b1-2321-4c12-88b1-755bd5ad6302_1\u0027.
File name: \u0027/tmp/c521a9b1-2321-4c12-88b1-755bd5ad6302_1\u0027
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean\u0026 wasSymlink, Func\u00604 createOpenException)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64\u0026 fileLength, UnixFileMode\u0026 filePermissions, Boolean failForSymlink, Boolean\u0026 wasSymlink, Func\u00604 createOpenException)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable\u00601 unixCreateMode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at Microsoft.Diagnostics.Monitoring.WebApi.DumpService.AutoDeleteFileStream..ctor(String path)
   at Microsoft.Diagnostics.Monitoring.WebApi.DumpService.DumpAsync(IEndpointInfo endpointInfo, DumpType mode, CancellationToken token)
   at Microsoft.Diagnostics.Tools.Monitor.DumpOperation.ExecuteAsync(Stream outputStream, CancellationToken token)
   at Microsoft.Diagnostics.Monitoring.WebApi.OutputStreamResult.\u003C\u003Ec__DisplayClass6_0.\u003C\u003CExecuteResultAsync\u003Eb__0\u003Ed.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Diagnostics.Monitoring.WebApi.ActionContextExtensions.\u003C\u003Ec__DisplayClass1_0.\u003C\u003CInvokeAsync\u003Eb__0\u003Ed.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Diagnostics.Monitoring.WebApi.ExecutionHelper.InvokeAsync[T](Func\u00602 action, ILogger logger, CancellationToken token)
   at Microsoft.Diagnostics.Monitoring.WebApi.ActionContextExtensions.InvokeAsync(ActionContext context, Func\u00602 action, ILogger logger)
   at Microsoft.Diagnostics.Monitoring.WebApi.OutputStreamResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\u003CInvokeNextResultFilterAsync\u003Eg__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State\u0026 next, Scope\u0026 scope, Object\u0026 state, Boolean\u0026 isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\u003CInvokeResultFilters\u003Eg__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\u003CInvokeFilterPipelineAsync\u003Eg__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\u003CInvokeAsync\u003Eg__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\u003CInvokeAsync\u003Eg__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication\u00601 application)","State":{"Message":"Connection id \u00220HN69KRQHJ5GA\u0022, Request id \u00220HN69KRQHJ5GA:00000001\u0022: An unhandled exception was thrown by the application.","ConnectionId":"0HN69KRQHJ5GA","TraceIdentifier":"0HN69KRQHJ5GA:00000001","{OriginalFormat}":"Connection id \u0022{ConnectionId}\u0022, Request id \u0022{TraceIdentifier}\u0022: An unhandled exception was thrown by the application."},"Scopes":[{"Message":"SpanId:6b683e14ebdaf084, TraceId:e1c3ccd331b318df402a1dbc83a4175e, ParentId:0000000000000000","SpanId":"6b683e14ebdaf084","TraceId":"e1c3ccd331b318df402a1dbc83a4175e","ParentId":"0000000000000000"},{"Message":"ConnectionId:0HN69KRQHJ5GA","ConnectionId":"0HN69KRQHJ5GA"},{"Message":"RequestPath:/dump RequestId:0HN69KRQHJ5GA:00000001","RequestId":"0HN69KRQHJ5GA:00000001","RequestPath":"/dump"}]}
github-actions[bot] commented 2 weeks ago

Welcome to dotnet-monitor!

Thanks for creating your first issue; let us know what you think of dotnet-monitor by filling out our survey.

jander-msft commented 1 week ago

In your configuration, you've instructed .NET Monitor to tell the application process to store the dump files into /tmp via

DOTNETMONITOR_Storage__DumpTempFolder=/tmp

However, the /tmp directory is not shared between the two containers. So while the dump file will be in the /tmp directory in the application container, the .NET Monitor container has its own /tmp directory and thus cannot get the dump file.

You either need to:

  1. have a volume that is mounted at /tmp in both containers, or
  2. remove the DOTNETMONITOR_Storage__DumpTempFolder setting and just let .NET Monitor use the default shared path. In your configuration, the dumps will be somewhere under the /diagnostics directory.