FiloSottile / Heartbleed

A checker (site and tool) for CVE-2014-0160
http://filippo.io/Heartbleed
MIT License
2.31k stars 465 forks source link

Removes race condition #86

Closed sudorandom closed 9 years ago

sudorandom commented 10 years ago

There's currently a data race when setting and accessing the closeNotifySent boolean value. I've solved this with the addition of a channel and a new non-blocking select statement.

Before this change (sad tests):

$ go test ./... -race
?       _/home/kevin/Checkouts/Heartbleed   [no test files]
==================
WARNING: DATA RACE
Read by goroutine 11:
  _/home/kevin/Checkouts/Heartbleed/bleed.func·001()
      /home/kevin/Checkouts/Heartbleed/bleed/heartbleed.go:108 +0x23f

Previous write by goroutine 12:
  _/home/kevin/Checkouts/Heartbleed/bleed.func·002()
      /home/kevin/Checkouts/Heartbleed/bleed/heartbleed.go:126 +0x74

Goroutine 11 (running) created at:
  _/home/kevin/Checkouts/Heartbleed/bleed.Heartbleed()
      /home/kevin/Checkouts/Heartbleed/bleed/heartbleed.go:120 +0x79f
  _/home/kevin/Checkouts/Heartbleed/bleed.TestBleedELB()
      /home/kevin/Checkouts/Heartbleed/bleed/bleed_test.go:24 +0x1fb
  testing.tRunner()
      /home/kevin/Checkouts/go/src/pkg/testing/testing.go:391 +0x10f

Goroutine 12 (finished) created at:
  _/home/kevin/Checkouts/Heartbleed/bleed.Heartbleed()
      /home/kevin/Checkouts/Heartbleed/bleed/heartbleed.go:127 +0x814
  _/home/kevin/Checkouts/Heartbleed/bleed.TestBleedELB()
      /home/kevin/Checkouts/Heartbleed/bleed/bleed_test.go:24 +0x1fb
  testing.tRunner()
      /home/kevin/Checkouts/go/src/pkg/testing/testing.go:391 +0x10f
==================
PASS
Found 1 data race(s)
FAIL    _/home/kevin/Checkouts/Heartbleed/bleed 7.971s
?       _/home/kevin/Checkouts/Heartbleed/bleed/tls [no test files]
?       _/home/kevin/Checkouts/Heartbleed/logger    [no test files]
?       _/home/kevin/Checkouts/Heartbleed/server    [no test files]
?       _/home/kevin/Checkouts/Heartbleed/server/cache  [no test files]

After this change (happy tests):

$ go test ./... -race
?     _/home/kevin/Checkouts/Heartbleed [no test files]
ok    _/home/kevin/Checkouts/Heartbleed/bleed 7.998s
?     _/home/kevin/Checkouts/Heartbleed/bleed/tls [no test files]
?     _/home/kevin/Checkouts/Heartbleed/logger  [no test files]
?     _/home/kevin/Checkouts/Heartbleed/server  [no test files]
?     _/home/kevin/Checkouts/Heartbleed/server/cache  [no test files]