-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
App does not Run as a service in a Windows Container #52416
Comments
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsDescriptionUsing the library
When executing as a service in a Windows Container the following can be observed: System event logs:
Application event logs:
It appears the the "host" (that the right name?) does not detect it's running as a service. So the app defaults to running as a console app. Digging deeper, there's a check for "am I a service?" in runtime/src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/WindowsServiceHelpers.cs Lines 18 to 31 in 01b7e73
Looking at what this checks:
Apparently Other informationWhile "why are running an app in a Windows Container as a Windows Service? Don't do that." would be a completely valid answer.... We are using Windows Containers to provide short lived sandboxes for integration tests - in this case - testing a Wix installer, installing a .NET 5 based Windows Service (self-contained mode). It would be nice if we could continue doing so with .NET 5. We were historically using TopShelf under .NET Framework, but we migrated to .NET 5. TopShelf does not perform this session 0 check, only the Therefore, I propose removing that session id check going forward.
|
If this proposal is acceptable, I would be happy to make a pr. 😸 |
Getting help from @GrabYourPitchforks offline, the following approach was recommended for identifying if the current process is hosted as a windows service:
We can accomplish (1) above with calling: Lines 694 to 701 in 14d6532
Then p/invoke into QueryServiceStatusEx to get the service's PID. Comparing the current PID is straight-forward from there. Moving to 7.0 and marking as "up for grabs". |
Sounds good! I'll see if I have time to work this in the near future. |
I'm not going to be able to work this any time soon. Needing to install native build sdk's/python, modifying PATH, etc. is a bit heavy for my current setup. I don't suppose there's a way to work extensions without needing to build the whole runtime? |
Check out @ViktorHofer's response here: You can build the
and you can run the
So you can do some development without building the whole runtime. |
Oh, thanks - I didn't think about not building the solution (related to the Directory.Build.props I assume?). My tooling hates this solution - removing the |
I am trying to fix this issue but unfortunately, the described solution does not work. QueryServiceStatusEx return 0 for service. I think, this happens because service is not running yet, it has status StartPending (I checked it) on the moment when we call QueryServiceStatusEx. You could see my code here: wrzucher@e5ade03 So, I don't know how this problem could be fixed. |
The reporter proposes to delete session id check. Isn't it enough? Do you think it can cause some side-effects? |
Please review #51269 (comment) as the cause of the issue may not be related only to the SessionId validation.
Is it possible that the "service" is not being created and spawned as an actual Windows Service but rather as a stand alone executable which expected behavior is to continue running at infinitum? |
I hit this issue as well and can confirm that getting rid of the |
Removing SessionId check in IsWindowsService(). This check is not correct when the process is being run in a Windows container. The container will get a different SessionId. Fix dotnet#52416
I've created #62452 to remove the check. |
Removing SessionId check in IsWindowsService(). This check is not correct when the process is being run in a Windows container. The container will get a different SessionId. Fix #52416
Removing SessionId check in IsWindowsService(). This check is not correct when the process is being run in a Windows container. The container will get a different SessionId. Fix dotnet#52416
Description
Using the library
Microsoft.Extensions.Hosting.WindowsServices
and a builder like the following:When executing as a service in a Windows Container the following can be observed:
System event logs:
Application event logs:
It appears the the "host" (that the right name?) does not detect it's running as a service. So the app defaults to running as a console app.
Digging deeper, there's a check for "am I a service?" in
Microsoft.Extensions.Hosting.WindowsServices.IsWindowsService()
.runtime/src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/WindowsServiceHelpers.cs
Lines 18 to 31 in 01b7e73
Looking at what this checks:
services
? Yes.0
? No?!?Apparently
services
doesn't have to run under session 0?Other information
While "why are running an app in a Windows Container as a Windows Service? Don't do that." would be a completely valid answer.... We are using Windows Containers to provide short lived sandboxes for integration tests - in this case - testing a Wix installer, installing a .NET 5 based Windows Service (self-contained mode). It would be nice if we could continue doing so with .NET 5.
We were historically using TopShelf under .NET Framework, but we migrated to .NET 5. TopShelf does not perform this session 0 check, only the
services
name check: https://github.com/Topshelf/Topshelf/blob/03bde8963da8c057ffc6df07ef9600ffdf6047c1/src/Topshelf/Runtime/DotNetCore/DotNetCoreHostEnvironment.cs#L57-L80Therefore, I propose removing that session id check going forward.
The text was updated successfully, but these errors were encountered: