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

x/sys/windows/svc: test failures with "The specified service has been marked for deletion." #42211

Closed
bcmills opened this issue Oct 26, 2020 · 10 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@bcmills bcmills added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 26, 2020
@gopherbot gopherbot added this to the Unreleased milestone Oct 26, 2020
@networkimprov
Copy link

cc @mattn

@alexbrainman
Copy link
Member

@bcmills thank you for creating this issue.

The error message is ERROR_SERVICE_MARKED_FOR_DELETE returned from DeleteService

https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-deleteservice

Interestingly, when we see a failure, both golang.org/x/sys/windows/svc and golang.org/x/sys/windows/svc/mgr tests fail. To me this sounds like package tests interfere with each other. In fact both test install the same service (same name and source). I wonder, if golang.org/x/sys/windows/svc and golang.org/x/sys/windows/svc/mgr run at the same time. Is this possible? If yes, then this can certainly happen.

I have seen this error before DeleteService was run while service process was still running.

I have also run

for /l %i in (1 1 10) do go test -count=1 golang.org/x/sys/windows/svc/...

and this command runs fine.

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>go test -count=1 golang.org/x/sys/windows/svc/...
ok      golang.org/x/sys/windows/svc    3.475s
?       golang.org/x/sys/windows/svc/debug      [no test files]
ok      golang.org/x/sys/windows/svc/eventlog   0.057s
?       golang.org/x/sys/windows/svc/example    [no test files]
ok      golang.org/x/sys/windows/svc/mgr        0.108s

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>go test -count=1 golang.org/x/sys/windows/svc/...
ok      golang.org/x/sys/windows/svc    3.508s
?       golang.org/x/sys/windows/svc/debug      [no test files]
ok      golang.org/x/sys/windows/svc/eventlog   0.061s
?       golang.org/x/sys/windows/svc/example    [no test files]
ok      golang.org/x/sys/windows/svc/mgr        0.056s

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>go test -count=1 golang.org/x/sys/windows/svc/...
ok      golang.org/x/sys/windows/svc    3.410s
?       golang.org/x/sys/windows/svc/debug      [no test files]
ok      golang.org/x/sys/windows/svc/eventlog   0.112s
?       golang.org/x/sys/windows/svc/example    [no test files]
ok      golang.org/x/sys/windows/svc/mgr        0.069s

But, if I interrupt my test by pressing Ctrl+C, this happens

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>go test -count=1 golang.org/x/sys/windows/svc/...
exit status 3221225786
FAIL    golang.org/x/sys/windows/svc    1.339s
?       golang.org/x/sys/windows/svc/debug      [no test files]
ok      golang.org/x/sys/windows/svc/eventlog   0.076s

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>

and I can see service process is still running. I used Process Explorer

https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer

and I know service executable is called a.exe

image

And indeed, if I start my test again, I see the error.

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>for /l %i in (1 1 10) do go test -count=1 golang.org/x/sys/windows/svc/...

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>go test -count=1 golang.org/x/sys/windows/svc/...
--- FAIL: TestExample (0.58s)
    svc_test.go:82: Delete failed: The specified service has been marked for deletion.
FAIL
FAIL    golang.org/x/sys/windows/svc    0.633s
?       golang.org/x/sys/windows/svc/debug      [no test files]
ok      golang.org/x/sys/windows/svc/eventlog   0.060s
?       golang.org/x/sys/windows/svc/example    [no test files]

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>

But, if I stop service with

sc stop myservice

I can see a.exe process disappears. And I can run my test again.

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>for /l %i in (1 1 10) do go test -count=1 golang.org/x/sys/windows/svc/...

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>go test -count=1 golang.org/x/sys/windows/svc/...
ok      golang.org/x/sys/windows/svc    3.500s
?       golang.org/x/sys/windows/svc/debug      [no test files]
ok      golang.org/x/sys/windows/svc/eventlog   0.087s
?       golang.org/x/sys/windows/svc/example    [no test files]
ok      golang.org/x/sys/windows/svc/mgr        0.081s

c:\Users\Alex\dev\src\golang.org\x\sys\windows\svc>go test -count=1 golang.org/x/sys/windows/svc/...
ok      golang.org/x/sys/windows/svc    3.583s
?       golang.org/x/sys/windows/svc/debug      [no test files]
ok      golang.org/x/sys/windows/svc/eventlog   0.060s
?       golang.org/x/sys/windows/svc/example    [no test files]
ok      golang.org/x/sys/windows/svc/mgr        0.067s

Alex

@bcmills
Copy link
Member Author

bcmills commented Nov 3, 2020

I wonder, if golang.org/x/sys/windows/svc and golang.org/x/sys/windows/svc/mgr run at the same time. Is this possible?

Yes, tests of different packages can and often do run at the same time.

@zx2c4
Copy link
Contributor

zx2c4 commented Nov 3, 2020

Using a random service name might help

@gopherbot
Copy link

Change https://golang.org/cl/267603 mentions this issue: windows/svc: stop service before deletion in TestExample

@gopherbot
Copy link

Change https://golang.org/cl/267604 mentions this issue: windows/svc/mgr: rename service in TestMyService

@alexbrainman
Copy link
Member

Yes, tests of different packages can and often do run at the same time.

I am surprised. Are you talking about builders or go test command in general?

Using a random service name might help

Good half-advice. I will rename service in one of the tests - that should be good enough. I don't like the random bit - it is easier to manage / write code when things have known predefined names.

Thank you.

Alex

@bcmills
Copy link
Member Author

bcmills commented Nov 5, 2020

Yes, tests of different packages can and often do run at the same time.

I am surprised. Are you talking about builders or go test command in general?

Both? Note that it is also possible for a user to run go test on a package multiple times simultaneously. For example, I often run go test -short ./... in one terminal and go test -race ./... simultaneously in another. The golang.org/x/... tests should be written such that they reliably pass when run that way.

@bcmills
Copy link
Member Author

bcmills commented Nov 5, 2020

(The -p flag controls how many test binaries a single invocation of go test can run in parallel; see https://tip.golang.org/cmd/go/#hdr-Compile_packages_and_dependencies.)

@alexbrainman
Copy link
Member

For example, I often run go test -short ./... in one terminal and go test -race ./... simultaneously in another.

I don't do that.

The golang.org/x/... tests should be written such that they reliably pass when run that way.

No argument from me.

The -p flag controls how many test binaries a single invocation of go test can run in parallel;

Sure. I hardly ever use anything more than go test.

Alex

gopherbot pushed a commit to golang/sys that referenced this issue Nov 6, 2020
TestExample normally stops and deletes test service at the end of the
test. But, if TestExample does not complete for some reason, test
service might remain running and installed.

There is some code that deletes "left over" test service before starting
the test. But that code fails, if service is running. Deletion only
works, if service is not running. This CL adds code to stop the "left
over" service so it can be deleted.

Update golang/go#42211

Change-Id: I826dd587063265c5b96076668c3704c0a7eaa3d8
Reviewed-on: https://go-review.googlesource.com/c/sys/+/267603
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Nov 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants