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

ServiceController tests fail to start test service #1262

Closed
danmoseley opened this issue Jan 3, 2020 · 4 comments · Fixed by #34802
Closed

ServiceController tests fail to start test service #1262

danmoseley opened this issue Jan 3, 2020 · 4 comments · Fixed by #34802
Assignees
Labels
area-System.ServiceProcess untriaged New issue has not been triaged by the area owner

Comments

@danmoseley
Copy link
Member

These tests verify ServiceBase and ServiceController but are rarely run because you need to specify outerloop AND you have to be elevated. They currently are failing for me -- I tried two machines.

C:\git\runtime\src\libraries\System.ServiceProcess.ServiceController\tests>msbuild /t:rebuildandtest /p:outerloop=true
...
...
    Discovering: System.ServiceProcess.ServiceController.Tests (method display = ClassAndMethod, method display options
   = None)
    Discovered:  System.ServiceProcess.ServiceController.Tests (found 36 of 37 test cases)
    Starting:    System.ServiceProcess.ServiceController.Tests (parallel test collections = on, max threads = 4)...

       System.InvalidOperationException : Cannot start service '4cb85dca-edbf-430c-afe2-61f5d782f266.Dependent' on com
  puter '.'.
        ---- System.ComponentModel.Win32Exception : Access is denied.
        Stack Trace:
          C:\git\runtime\src\libraries\System.ServiceProcess.ServiceController\src\System\ServiceProcess\ServiceControl
  ler.cs(844,0): at System.ServiceProcess.ServiceController.Start(String[] args)
          C:\git\runtime\src\libraries\System.ServiceProcess.ServiceController\src\System\ServiceProcess\ServiceControl
  ler.cs(804,0): at System.ServiceProcess.ServiceController.Start()
          C:\git\runtime\src\libraries\System.ServiceProcess.ServiceController\tests\System.ServiceProcess.ServiceContr
  oller.TestService\TestServiceInstaller.cs(106,0): at System.ServiceProcess.Tests.TestServiceInstaller.Install()
          C:\git\runtime\src\libraries\System.ServiceProcess.ServiceController\tests\TestServiceProvider.cs(123,0): at
  System.ServiceProcess.Tests.TestServiceProvider.CreateTestServices()
          C:\git\runtime\src\libraries\System.ServiceProcess.ServiceController\tests\TestServiceProvider.cs(77,0): at S
  ystem.ServiceProcess.Tests.TestServiceProvider..ctor(String serviceName, String userName)
          C:\git\runtime\src\libraries\System.ServiceProcess.ServiceController\tests\TestServiceProvider.cs(62,0): at S
  ystem.ServiceProcess.Tests.TestServiceProvider..ctor()
          C:\git\runtime\src\libraries\System.ServiceProcess.ServiceController\tests\ServiceControllerTests.cs(24,0): a
  t System.ServiceProcess.Tests.ServiceControllerTests..ctor()
          ----- Inner Stack Trace -----

This is definitely an elevated prompt. I tried Debugger.Launch() in the TestService constructor, and it does not fire. I looked at the Security event log, and it does not have any "failed" messages. "net start " gives access denied as well. So it's not the test harness.

@Anipik do you repro this?

@ericstj
Copy link
Member

ericstj commented Feb 27, 2020

Looks like this is similar issue to what @danmosemsft mentioned here: #24571 (comment)

Same thing happening for me. I poked around at it a bit and found I could get past the access denied error by granting LocalService Read permission on my artifacts folder. Once doing that (and disabling the active issue attribute) I can repro the issue #1724. So it seems to be a permissions issue.

Here's the command I used to fix it:

icacls C:\src\dotnet\runtime\artifacts /grant "NT AUTHORITY\LocalService":(OI)(CI)(R)

@ericstj
Copy link
Member

ericstj commented Feb 27, 2020

An alternative to fixing this would be to run the test services as LocalSystem instead (by passing null for username), which doesn't require special permissions. I'm not fixing this ATM because I haven't looked deeply enough to understand if it's intentional that we test as LocalService.

@danmoseley
Copy link
Member Author

@ericstj re localservice --

// The default username for installing the service is NT AUTHORITY\\LocalService which does not have access to EventLog.
// If the username is null, then the service is created under LocalSystem Account which have access to EventLog.

@danmoseley
Copy link
Member Author

The event log is only relevant because the tests are trying to verify ServiceBase.AutoLog property.

Perhaps we could use LocalService for all the other tests, and fail gracefully if needed for the AutoLog tests. Or, just stop testing AutoLog.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Dec 9, 2021
We shouldn't need to see the unconstructed types at runtime for anything.

Fixes dotnet#1262.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.ServiceProcess untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants