Skip to content

Commit

Permalink
ref: add comment why save registration in variable
Browse files Browse the repository at this point in the history
  • Loading branch information
m.tre committed Jun 18, 2024
1 parent 54e1e21 commit b94a13e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Vostok.Hosting/VostokHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class VostokHost
private volatile VostokHostingEnvironment environment;
private volatile ILog log;
#if NET6_0_OR_GREATER
private volatile PosixSignalRegistration sigtermRegistration;
private volatile PosixSignalRegistration? sigtermRegistration;

Check warning on line 58 in Vostok.Hosting/VostokHost.cs

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest, nuget)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 58 in Vostok.Hosting/VostokHost.cs

View workflow job for this annotation

GitHub Actions / build / build (macos-12, nuget)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 58 in Vostok.Hosting/VostokHost.cs

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest, cement)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 58 in Vostok.Hosting/VostokHost.cs

View workflow job for this annotation

GitHub Actions / build / build (macos-12, cement)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 58 in Vostok.Hosting/VostokHost.cs

View workflow job for this annotation

GitHub Actions / build / build (windows-latest, nuget)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 58 in Vostok.Hosting/VostokHost.cs

View workflow job for this annotation

GitHub Actions / build / build (windows-latest, cement)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
#endif

public VostokHost([NotNull] VostokHostSettings settings)
Expand Down Expand Up @@ -177,6 +177,8 @@ public Task<VostokApplicationRunResult> StopAsync(bool ensureSuccess = true)
public VostokHost RegisterSigtermCancellation()
{
#if NET6_0_OR_GREATER
// Saving PosixSignalRegistration to variable, because of IDisposable inheritance,
// and GC will collect if not assigned. On Dispose handler will unregister.
sigtermRegistration = PosixSignalRegistration.Create(PosixSignal.SIGTERM, ctx =>
{
ctx.Cancel = true;
Expand All @@ -199,6 +201,9 @@ private async Task<VostokApplicationRunResult> RunInternalAsync()

var dynamicThreadPool = ConfigureDynamicThreadPool();

#if NET6_0_OR_GREATER
using (sigtermRegistration)
#endif
using (environment)
using (new ApplicationDisposable(settings.Application, environment, log))
using (dynamicThreadPool)
Expand Down

0 comments on commit b94a13e

Please sign in to comment.