Unsafe use of clock_seq
GoogleCodeExporter opened this issue · 3 comments
GoogleCodeExporter commented
In GetTime, the clock_seq variable is updated inside a mutex. However, when
NewUUID accesses the clock_seq, it is outside of this lock. As a result a race
condition exists where multiple threads will update the clock_seq in an atomic
fashion, but each of them will generate a UUID with the same value.
I have included a patch file which implements a possible fix.
I have also attached test.go, which illustrates the problem. The following
results were produced on an 8-core 4Ghz machine with 32gb of ram:
2014/12/01 04:01:04 Creating Channels
2014/12/01 04:01:04 Starting Threads
2014/12/01 04:01:04 Wating for Completion
2014/12/01 04:01:06 Processing Data. Execution took: 2.0741186s
2014/12/01 04:01:13 Found duplicate UUID!!!
2014/12/01 04:01:13 Found duplicate UUID!!!
2014/12/01 04:01:16 Found duplicate UUID!!!
2014/12/01 04:01:17 Found duplicate UUID!!!
2014/12/01 04:01:18 Found duplicate UUID!!!
2014/12/01 04:01:18 Found duplicate UUID!!!
2014/12/01 04:01:19 Found duplicate UUID!!!
2014/12/01 04:01:20 Found duplicate UUID!!!
2014/12/01 04:01:22 Found duplicate UUID!!!
2014/12/01 04:01:23 Found duplicate UUID!!!
2014/12/01 04:01:23 Found duplicate UUID!!!
2014/12/01 04:01:26 Found duplicate UUID!!!
2014/12/01 04:01:26 Done.
The following test is after the patch is applied:
2014/12/01 04:01:44 Creating Channels
2014/12/01 04:01:44 Starting Threads
2014/12/01 04:01:44 Wating for Completion
2014/12/01 04:01:46 Processing Data. Execution took: 2.0071148s
2014/12/01 04:02:06 Done.
Original issue reported on code.google.com by rob...@rfhp.net
on 1 Dec 2014 at 9:33
Attachments:
GoogleCodeExporter commented
Original comment by bor...@google.com
on 1 Dec 2014 at 6:07
- Changed state: Fixed
GoogleCodeExporter commented
Thanks for the very fast turn-around time. I'm happy that I'll get to use this
in my project and that I don't have to change everything to use a modified
clone for the next update. I really appreciate it.
Original comment by rob...@rfhp.net
on 1 Dec 2014 at 6:44
GoogleCodeExporter commented
Thanks for the report. I am building a fix based on your code, and also am
adding a regression test to test for this condition. The regression test will
only be run when "--regressions" is specified on the go test command line.
Original comment by bor...@google.com
on 1 Dec 2014 at 5:22
- Changed state: Started