Skip to content

Handle error when SSH agent is not accessible (in Docker) #41

Description

@OlivierBouchoms

The container fails to connect to the SSH auth sock. An empty response body is returned. This happens when running the Docker Compose application in Linux.

If this happens, the API should handle the exception gracefully and return an error with code SshAgentNotAccessible. The frontend should display this error, so the user can properly troubleshoot.

Error log:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HNIE2TGKU63Q", Request id "0HNIE2TGKU63Q:00000002": An unhandled exception was thrown by the application.
      System.Net.Sockets.SocketException (111): Connection refused /run/user/1000/keyring/ssh
         at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
         at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
         at SshNet.Agent.SshAgentSocketStream..ctor(String socketPath, TimeSpan timeout)
         at SshNet.Agent.SshAgent.Send(IAgentMessage message)
         at SshNet.Agent.SshAgent.RequestIdentities()
         at SqliteRemoteApi.Factory.SshClientFactory.CreateSshClient(SshHost host) in /app/Factory/SshClientFactory.cs:line 25
         at SqliteRemoteApi.Manager.SqLiteDatabaseManager.Connect(String hostName, String dbPath) in /app/Manager/SqLiteDatabaseManager.cs:line 265
         at SqliteRemoteApi.Manager.SqLiteDatabaseManager.Connect(DatabaseConnectInput input) in /app/Manager/SqLiteDatabaseManager.cs:line 35
         at SqliteRemoteApi.Controllers.ServerController.Connect(ServerConnectRequestDto dto) in /app/Controllers/ServerController.cs:line 18
         at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 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.<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__Logged|17_1(ResourceInvoker invoker)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
         at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthostingApplication runtime

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions