@@ -37,8 +37,6 @@ type Watchdog struct {
37
37
restartTimeout time.Duration
38
38
// stopped indicates whether Watchdog was stopped.
39
39
stopped bool
40
- // stopMutex used to avoid a race condition under stopped field.
41
- stopMutex sync.Mutex
42
40
// done channel used to inform the signal handle goroutine
43
41
// about termination of the Instance.
44
42
done chan bool
@@ -73,16 +71,11 @@ func (wd *Watchdog) Start() {
73
71
}
74
72
wd .logger = wd .Instance .logger
75
73
// Start the Instance and forwarding signals (except SIGINT and SIGTERM)
76
- wd .startSignalHandling ()
77
- wd .stopMutex .Lock ()
78
- if ! wd .stopped {
79
- if err := wd .Instance .Start (); err != nil {
80
- wd .logger .Printf (`Watchdog(ERROR): "%v".` , err )
81
- wd .stopMutex .Unlock ()
82
- break
83
- }
74
+ if err := wd .Instance .Start (); err != nil {
75
+ wd .logger .Printf (`Watchdog(ERROR): "%v".` , err )
76
+ break
84
77
}
85
- wd .stopMutex . Unlock ()
78
+ wd .startSignalHandling ()
86
79
87
80
// Wait while the Instance will be terminated.
88
81
if err := wd .Instance .Wait (); err != nil {
@@ -136,12 +129,10 @@ func (wd *Watchdog) startSignalHandling() {
136
129
case sig := <- sigChan :
137
130
switch sig {
138
131
case syscall .SIGINT , syscall .SIGTERM :
139
- wd .stopMutex .Lock ()
140
132
wd .Instance .Stop (30 * time .Second )
141
133
// If we receive one of the "stop" signals, the
142
134
// program should be terminated.
143
135
wd .stopped = true
144
- wd .stopMutex .Unlock ()
145
136
case syscall .SIGHUP :
146
137
// Rotate the log files.
147
138
wd .logger .Rotate ()
0 commit comments