Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1328)

Issue 98480046: worker: fix simpleworker Kill

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 11 months ago by axw
Modified:
9 years, 11 months ago
Reviewers:
mp+220563, wallyworld, rog
Visibility:
Public.

Description

worker: fix simpleworker Kill gccgo does not like it when you close a channel twice. It's not a very nice thing anyway. Fixes lp:1308852 https://code.launchpad.net/~axwalk/juju-core/lp1308852-worker-simple-gccgo/+merge/220563 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+8 lines, -8 lines) Patch
A [revision details] View 1 chunk +2 lines, -0 lines 0 comments Download
M worker/simpleworker.go View 2 chunks +6 lines, -8 lines 1 comment Download

Messages

Total messages: 3
axw
Please take a look.
9 years, 11 months ago (2014-05-22 05:29:49 UTC) #1
wallyworld
LGTM
9 years, 11 months ago (2014-05-22 06:13:30 UTC) #2
rog
9 years, 11 months ago (2014-05-22 08:38:34 UTC) #3
https://codereview.appspot.com/98480046/diff/1/worker/simpleworker.go
File worker/simpleworker.go (right):

https://codereview.appspot.com/98480046/diff/1/worker/simpleworker.go#newcode35
worker/simpleworker.go:35: case w.stopc <- struct{}{}:
This isn't quite right because it changes the NewSimpleWorker contract, which
states that stopCh is closed when the worker is killed, which means that we can
read from the channel any number of times after it's been closed.

If we want to avoid the recover check (which is something that gccgo really
should allow, but that's a different issue) the correct solution is to have a
mutex that guards the close and do something like this:

w.killMutex.Lock()
defer w.killMutex.Unlock()
select {
case <-w.stopc:
    return  // stopc is already closed
default:
    close(w.stopc)
}
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b