programing

원격 Ubuntu 시스템에서 시도/캐치 선량이 탐지되지 않음

instargram 2023. 6. 6. 00:25
반응형

원격 Ubuntu 시스템에서 시도/캐치 선량이 탐지되지 않음

제 앱에 예외가 잡히지 않아서 조금 당황스럽습니다.그러나 이 문제는 대여된 원격 컴퓨터에서만 발생합니다.시스템은 최신 닷넷 런타임 환경에서 Ubuntu 22.04를 실행합니다.

로컬 Windows 컴퓨터나 Docker에서 모든 것이 예상대로 작동합니다.연결이 설정되지 않으면 캐치 블록에 도달합니다. (클래식!내 컴퓨터에서 작동)

다음 기간 동안 오류가 발생합니다.await connection.OpenAsync()그리고 전체 앱이 종료됩니다.다음은 출력 창의 디버그 로그에 출력됩니다.

Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
The program '[77028] dotnet' has exited with code 0 (0x0).

데이터베이스 연결을 위해 https://mysqlconnector.net/ 의 커넥터를 Dapper와 연결하여 사용합니다.

제가 전혀 이해할 수 없는 것은 그 방법이 다른 응용 프로그램에서도 사용되고 동일한 기계에서 문제 없이 작동한다는 것입니다.

이상한 행동을 하는 방법.

private async Task<MySqlConnection> GetDbConnectionAsync()
{
    Exception? connectionException = default;
    foreach (var connectionString in _connectionStrings)
    {
        var dbHost = connectionString.Split(';')
                                     .First(s => s.Contains("Server", StringComparison.OrdinalIgnoreCase))
                                     .Split('=')[1];
        try
        {
            // Open database connection async
            var connection = new MySqlConnection(connectionString);
            await connection.OpenAsync(); // <-- THIS CRASHING THE APPLICATION

            // Set connection session variables
            await SetSessionVars(connection);

            return connection;
        }
        catch (Exception ex)
        {
            connectionException = ex;
            _log.LogError(ex,
                          $"[Data Access Layer]{Environment.NewLine}" +
                          $"Connection to database failed. Tried host: {dbHost}. Exception Message: {ex.Message}");
        }
    }

    _log.LogError($"[Data Access Layer]{Environment.NewLine}" +
                  "All configured database nodes are not reachable. Connection failure. Wait for 5 seconds and will retry.");
    await Task.Delay(5000);

    throw new
        InvalidOperationException("[Data Access Layer] All configured database nodes are not reachable. Connection failure. Wait for 5 seconds and will retry.",
                                  connectionException);
}

저는 모든 힌트에 정말 감사합니다.

네, 제 실수입니다.컴퓨터에 동일한 Kestrel Port 5000에서 Blazor 앱이 이미 실행되고 있습니다.이러한 문제에 직면한 모든 사용자에게 Debug -> Windows -> Exception settings 메뉴에서 모든 예외에 대해 실행을 중단하도록 설정하면 매우 유용할 수 있습니다.

여기에 이미지 설명 입력

백그라운드 서비스가 이미 시작되어 병렬로 실행되고 있기 때문에 Kestrel 웹 서버가 백그라운드에서 아직 완전히 시작되지 않았으며 백그라운드 서비스가 데이터베이스에 연결하려고 할 때 항상 IoException이 발생하는지 확인하기가 어려웠습니다.

디버깅 환경이 영향을 받지 않도록 예외 설정을 재설정하는 것을 잊지 마십시오.

언급URL : https://stackoverflow.com/questions/73954789/try-catch-dose-not-catch-on-remote-ubuntu-machine

반응형