Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
m.tre committed Jun 19, 2024
1 parent 1eb0c83 commit 078c74c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 9 additions & 6 deletions 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;
#endif

public VostokHost([NotNull] VostokHostSettings settings)
Expand Down Expand Up @@ -177,13 +177,16 @@ public Task<VostokApplicationRunResult> StopAsync(bool ensureSuccess = true)
public VostokHost RegisterSigtermCancellation()
{
#if NET6_0_OR_GREATER
// Saving PosixSignalRegistration to variable, because of IDisposable inheritance,
// Saving PosixSignalRegistration reference to nameof(VostokHost) field, because of IDisposable inheritance,
// and GC will collect if not assigned. On Dispose and finalize handler will unregister.
sigtermRegistration = PosixSignalRegistration.Create(PosixSignal.SIGTERM, ctx =>
if (sigtermRegistration == null)
{
ctx.Cancel = true;
this.Stop(false);
});
sigtermRegistration = PosixSignalRegistration.Create(PosixSignal.SIGTERM, ctx =>
{
ctx.Cancel = true;
this.Stop(false);
});
}
#else
AppDomain.CurrentDomain.ProcessExit += (_, _) => this.Stop(false);
#endif
Expand Down
4 changes: 3 additions & 1 deletion Vostok.Hosting/VostokHost_Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public static VostokHost WithConsoleCancellation([NotNull] this VostokHost vosto
return vostokHost;
}

[Obsolete("Use VostokHost.RegisterSigtermCancellation instead of this")]
/// <summary>
/// Makes same as <see cref="VostokHost.RegisterSigtermCancellation"/>
/// </summary>
public static VostokHost WithSigtermCancellation([NotNull] this VostokHost vostokHost) =>
vostokHost.RegisterSigtermCancellation();
}
Expand Down

0 comments on commit 078c74c

Please sign in to comment.