all repos — captcha @ 885d67a665b23fc74a79bbcfd12093c8a0acae6c

Go package captcha implements generation and verification of image and audio CAPTCHAs.

store: fix potential race.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 19:16:09 +0200
commit

885d67a665b23fc74a79bbcfd12093c8a0acae6c

parent

60d32e9f9ce298d1a5346521baee4ca5eae61102

1 files changed, 5 insertions(+), 3 deletions(-)

jump to
M store.gostore.go

@@ -62,10 +62,12 @@ s.mu.Lock()

s.digitsById[id] = digits s.idByTime.PushBack(idByTimeValue{time.Seconds(), id}) s.numStored++ - s.mu.Unlock() - if s.numStored > s.collectNum { - go s.Collect() + if s.numStored <= s.collectNum { + s.mu.Unlock() + return } + s.mu.Unlock() + go s.Collect() } func (s *memoryStore) Get(id string, clear bool) (digits []byte) {