Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
Run the agent in the main gorountine to avoid race conditions on exit (
Browse files Browse the repository at this point in the history
  • Loading branch information
bmermet authored and Emanuele Palazzetti committed Oct 31, 2017
1 parent 38c9cff commit 004b00a
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions agent/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,28 @@ func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes c

exit := make(chan struct{})

go runAgent(exit)
elog.Info(0x40000003, ServiceName)
loop:
for {
select {
case c := <-r:
switch c.Cmd {
case svc.Interrogate:
changes <- c.CurrentStatus
// Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
time.Sleep(100 * time.Millisecond)
changes <- c.CurrentStatus
case svc.Stop, svc.Shutdown:
elog.Info(0x40000006, ServiceName)
close(exit)
break loop
default:
elog.Warning(0xc000000A, string(c.Cmd))
go func() {
for {
select {
case c := <-r:
switch c.Cmd {
case svc.Interrogate:
changes <- c.CurrentStatus
// Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
time.Sleep(100 * time.Millisecond)
changes <- c.CurrentStatus
case svc.Stop, svc.Shutdown:
elog.Info(0x40000006, ServiceName)
close(exit)
return
default:
elog.Warning(0xc000000A, string(c.Cmd))
}
}
}
}
}()
elog.Info(0x40000003, ServiceName)
runAgent(exit)

changes <- svc.Status{State: svc.StopPending}
return
Expand Down

0 comments on commit 004b00a

Please sign in to comment.