Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSVExceptionを適切にハンドリングする #33

Open
rioil opened this issue May 22, 2023 · 1 comment
Open

OSVExceptionを適切にハンドリングする #33

rioil opened this issue May 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@rioil
Copy link
Collaborator

rioil commented May 22, 2023

OSVExceptionが発生すると落ちます.

fail: Microsoft.Extensions.Hosting.Internal.Host[9]
      BackgroundService failed
      System.AggregateException: One or more errors occurred. (Exception of type 'OSV.Client.OSVException' was thrown.)
       ---> OSV.Client.OSVException: Exception of type 'OSV.Client.OSVException' was thrown.
       ---> System.Net.Http.HttpRequestException: Request failed with status code GatewayTimeout
         --- End of inner exception stack trace ---
         at Osmy.Server.Services.OSVClientEx.ExecuteAsync[T](RestRequest request, CancellationToken cancellationToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\OSVClientEx.cs:line 67
         at Osmy.Server.Services.OSVClientEx.QueryAffectedBatchAsync(BatchQueryEx batchQuery, CancellationToken cancellationToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\OSVClientEx.cs:line 51
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
         at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
         at Osmy.Server.Services.VulnerabilityScanner.<>c__DisplayClass8_1.<ExecuteBatchQueryAsync>b__1(Task`1 t) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\VulnerabilityScanner.cs:line 160
         at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
         at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
      --- End of stack trace from previous location ---
         at Osmy.Server.Services.VulnerabilityScanner.ScanPackageVulnerability(SbomPackageComponent[] pkgs, CancellationToken cancellationToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\VulnerabilityScanner.cs:line 98
         at Osmy.Server.Services.VulnerabilityScanner.ScanAllAsync(CancellationToken cancellationToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\VulnerabilityScanner.cs:line 47
         at Osmy.Server.Services.VulnerabilityScanService.StartAutoScanRequest(CancellationToken stoppingToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\VulnerabilityScanService.cs:line 38
         at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)
crit: Microsoft.Extensions.Hosting.Internal.Host[10]
      The HostOptions.BackgroundServiceExceptionBehavior is configured to StopHost. A BackgroundService has thrown an unhandled exception, and the IHost instance is stopping. To avoid this behavior, configure this to Ignore; however the BackgroundService will not be restarted.
      System.AggregateException: One or more errors occurred. (Exception of type 'OSV.Client.OSVException' was thrown.)
       ---> OSV.Client.OSVException: Exception of type 'OSV.Client.OSVException' was thrown.
       ---> System.Net.Http.HttpRequestException: Request failed with status code GatewayTimeout
         --- End of inner exception stack trace ---
         at Osmy.Server.Services.OSVClientEx.ExecuteAsync[T](RestRequest request, CancellationToken cancellationToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\OSVClientEx.cs:line 67
         at Osmy.Server.Services.OSVClientEx.QueryAffectedBatchAsync(BatchQueryEx batchQuery, CancellationToken cancellationToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\OSVClientEx.cs:line 51
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
         at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
         at Osmy.Server.Services.VulnerabilityScanner.<>c__DisplayClass8_1.<ExecuteBatchQueryAsync>b__1(Task`1 t) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\VulnerabilityScanner.cs:line 160
         at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
         at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
      --- End of stack trace from previous location ---
         at Osmy.Server.Services.VulnerabilityScanner.ScanPackageVulnerability(SbomPackageComponent[] pkgs, CancellationToken cancellationToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\VulnerabilityScanner.cs:line 98
         at Osmy.Server.Services.VulnerabilityScanner.ScanAllAsync(CancellationToken cancellationToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\VulnerabilityScanner.cs:line 47
         at Osmy.Server.Services.VulnerabilityScanService.StartAutoScanRequest(CancellationToken stoppingToken) in D:\rio\dev\CSharp\Osmy\Osmy.Server\Services\VulnerabilityScanService.cs:line 38
         at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)
@rioil rioil added the bug Something isn't working label May 22, 2023
@rioil
Copy link
Collaborator Author

rioil commented Jan 30, 2024

この部分でcatchしているので,落ちることは無くなっていますが,ログが出力が無く,例外が握りつぶされています.
そもそもこの例外はOSV側の問題なので,プログラムを異常終了させたり,脆弱性診断をスキップしてユーザーに通知したりするべきかもしれません.

try
{
var scanner = new VulnerabilityScanner();
await scanner.ScanAllAsync(stoppingToken);
var appNotificationService = new AppNotificationService();
appNotificationService.NotifyVulnerability();
}
catch (Exception)
{
// TODO logging
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant