Skip to content

Commit 4d1ba34

Browse files
authored
Fix various sync.Mutex double unlocks (#11)
1 parent e7884b0 commit 4d1ba34

File tree

3 files changed

+2
-6
lines changed

3 files changed

+2
-6
lines changed

examples/weather/services/poller/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Package poller implments a simple poller for the weather service.
2+
Package poller implements a simple poller for the weather service.
33
It consists of a Pulse worker that periodically calls the weather service
44
to retrieve the weather forecast for given US cities.
55
*/

pool/node.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ func (node *Node) ackWorkerEvent(ctx context.Context, ev *streaming.Event) {
488488
pending, ok := node.pendingEvents[key]
489489
if !ok {
490490
node.logger.Error(fmt.Errorf("received event %s from worker %s that was not dispatched", ack.EventID, workerID))
491-
node.lock.Unlock()
492491
return
493492
}
494493

pool/worker.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (w *Worker) stop(ctx context.Context) {
192192
w.lock.Lock()
193193
defer w.lock.Unlock()
194194
if w.stopped {
195-
w.lock.Unlock()
195+
return
196196
}
197197
w.stopped = true
198198
var err error
@@ -233,7 +233,6 @@ func (w *Worker) startJob(ctx context.Context, job *Job) error {
233233
w.lock.Lock()
234234
defer w.lock.Unlock()
235235
if w.stopped {
236-
w.lock.Unlock()
237236
return fmt.Errorf("worker %q stopped", w.ID)
238237
}
239238
job.Worker = w
@@ -251,7 +250,6 @@ func (w *Worker) stopJob(ctx context.Context, key string) error {
251250
w.lock.Lock()
252251
defer w.lock.Unlock()
253252
if w.stopped {
254-
w.lock.Unlock()
255253
return nil
256254
}
257255
if _, ok := w.jobs[key]; !ok {
@@ -270,7 +268,6 @@ func (w *Worker) notify(ctx context.Context, key string, payload []byte) error {
270268
w.lock.Lock()
271269
defer w.lock.Unlock()
272270
if w.stopped {
273-
w.lock.Unlock()
274271
w.logger.Debug("worker stopped, ignoring notification")
275272
return nil
276273
}

0 commit comments

Comments
 (0)