Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Process exit code not set when service fails to start/stop gracefully (v7) #120

Merged
merged 3 commits into from
Mar 22, 2017

Conversation

ramonsmits
Copy link
Member

The host uses (old) version 0.8.0 of the Topshelf project which seems to incorrect set the exit code when an errors happens during start/stop. An error could be as described in #119.

Magnum.StateMachine.StateMachineException: Exception occurred in Topshelf.Internal.ServiceController`1[[NServiceBus.Hosting.Windows.WindowsHost, NServiceBus.Host, Version=7.0.0.0, Culture=neutral, 

--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---

   at NServiceBus.Hosting.Windows.WindowsHost.Start() in C:\Build\src\NServiceBus.Hosting.Windows\WindowsHost.cs:line 30
   at Magnum.StateMachine.EventActionList`1.Execute(T stateMachine, Event event, Object parameter) in c:\Code\Topshelf\src\Topshelf\Internal\Hosts\ServiceHost.cs:line 0
   --- End of inner exception stack trace ---
   at Magnum.StateMachine.ExceptionActionDictionary`1.HandleException(T stateMachine, Event event, Object parameter, Exception exception) in c:\Code\Topshelf\src\Topshelf\Internal\Hosts\ServiceHost.cs:line 0

This PR is basically a workaround for the Topshelf error by calling Environment.Exit(int) ourselves. This results in the windows service to actually fail which results in Windows Service Recovery to kick in.

@ramonsmits ramonsmits changed the title Fixes #119 Process exit code not set when service fails to start/stop gracefully Mar 21, 2017
@ramonsmits ramonsmits changed the title Process exit code not set when service fails to start/stop gracefully Process exit code not set when service fails to start/stop gracefully (v7) Mar 21, 2017
@ramonsmits ramonsmits added this to the 7.0.1 milestone Mar 21, 2017
@ramonsmits
Copy link
Member Author

@Particular/nservicebus-maintainers @andreasohlund @sfarmar This seems to be a bug in Topshelf, this is a workaround.

Another option might be to update to a newer 1.0+ version of Topshelf but probably that has already deemed to much work as I also see Particular/NServiceBus#2201 about removing Topshelf.

Any reason that we use 0.8.0, as it seems to be very old.

@ramonsmits
Copy link
Member Author

Ok, digged a bit deeper and noticed this: https://github.com/Particular/Topshelf/commits/TopshelfForNSB which seems to be our fork.

@ramonsmits
Copy link
Member Author

WIthout looking at the implementation of Magnum I think this is why it fails: https://github.com/Particular/Topshelf/blob/TopshelfForNSB/src/Topshelf/Internal/ServiceController.cs#L76

@seanfarmar
Copy link
Contributor

seanfarmar commented Mar 22, 2017

@ramonsmits maybe we can get @andreasohlund to provide some context/history for this?

Otherwise, LGTM

@andreasohlund
Copy link
Member

Can't remember, John was the only one that made it into that code base and came back alive

@ramonsmits ramonsmits self-assigned this Mar 22, 2017
@ramonsmits ramonsmits changed the base branch from develop to hotfix-7.0.1 March 22, 2017 11:14
@ramonsmits ramonsmits merged commit 5b9ebe7 into hotfix-7.0.1 Mar 22, 2017
@seanfarmar seanfarmar deleted the service-start-failure branch September 12, 2017 16:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants