-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[release/7.0-staging] Make WindowsServiceLifetime gracefully stop #85656
Changes from all commits
701f7cc
f05ef3e
d7babd0
ba9608b
6254c6c
7dd0c7e
5f989c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.Win32.SafeHandles; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Advapi32 | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct SERVICE_STATUS_PROCESS | ||
{ | ||
public int dwServiceType; | ||
public int dwCurrentState; | ||
public int dwControlsAccepted; | ||
public int dwWin32ExitCode; | ||
public int dwServiceSpecificExitCode; | ||
public int dwCheckPoint; | ||
public int dwWaitHint; | ||
public int dwProcessId; | ||
public int dwServiceFlags; | ||
} | ||
|
||
private const int SC_STATUS_PROCESS_INFO = 0; | ||
|
||
[LibraryImport(Libraries.Advapi32, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
private static unsafe partial bool QueryServiceStatusEx(SafeServiceHandle serviceHandle, int InfoLevel, SERVICE_STATUS_PROCESS* pStatus, int cbBufSize, out int pcbBytesNeeded); | ||
|
||
internal static unsafe bool QueryServiceStatusEx(SafeServiceHandle serviceHandle, SERVICE_STATUS_PROCESS* pStatus) => QueryServiceStatusEx(serviceHandle, SC_STATUS_PROCESS_INFO, pStatus, sizeof(SERVICE_STATUS_PROCESS), out _); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
<EnableAOTAnalyzer>true</EnableAOTAnalyzer> | ||
<PackageDescription>.NET hosting infrastructure for Windows Services.</PackageDescription> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<ServicingVersion>1</ServicingVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
|
@@ -27,6 +29,7 @@ | |
|
||
<ItemGroup> | ||
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Hosting\src\Microsoft.Extensions.Hosting.csproj" /> | ||
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Logging.Abstractions\src\Microsoft.Extensions.Logging.Abstractions.csproj" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What code in WindowsServiceLifetime.cs caused the need to add this new project reference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this is the transitive dependency problem you described here, right? #85656 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. It's a side-effect of incremental servicing and our package testing caught it. Good reason to pay attention to those failures 👍 |
||
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Logging.EventLog\src\Microsoft.Extensions.Logging.EventLog.csproj" /> | ||
</ItemGroup> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the main PR I found no description for this change except "Fixing binding redirects for remote excutor". For my own education, would you mind explaining this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We weren't generating any bindingRedirects for tests, but they need them.
When running from XUnit we were working because XUnit has an AssemblyResolve hook that does a similar thing (though it can't do the exact same thing).
When I added out-of-proc services with RemoteExecutor -- really any use of remote executor -- loads failed since they didn't have this resolve handler. Ensuring the app.config is generated makes sure that remote executor gets it. It will also avoid us needing to rely on the AssemblyResolve hook in Xunit (and it's fragility).
Here's the discussion: #83892 (comment)