getamis / alice

Hierarchical Threshold Signature Scheme
Apache License 2.0
376 stars 75 forks source link

Fix race conditions #264

Closed markya0616 closed 1 year ago

markya0616 commented 1 year ago

This pull request is inspired by https://github.com/getamis/alice/pull/261. Fix the race condition issues

Checklist

papa-stiflera commented 1 year ago

The race conditions are still there

WARNING: DATA RACE
Write at 0x00c00031bcf4 by goroutine 136:
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.(*stopPeerManager).MustSend()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/1_enck_handler_test.go:203 +0xc4
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.(*pubkeyHandler).broadcast()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/0_pukkey_handler.go:186 +0x126
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.(*pubkeyHandler).Finalize()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/0_pukkey_handler.go:147 +0x4f
  github.com/getamis/alice/types/message.(*MsgMain).messageLoop()
      /home/skruglov/Projects/go/alice/types/message/msg_main.go:150 +0x40c
  github.com/getamis/alice/types/message.(*MsgMain).Start.func2()
      /home/skruglov/Projects/go/alice/types/message/msg_main.go:66 +0x4f

Previous read at 0x00c00031bcf4 by goroutine 40:
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.(*stopPeerManager).MustSend()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/1_enck_handler_test.go:196 +0x51
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.(*pubkeyHandler).broadcast()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/0_pukkey_handler.go:186 +0x161
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.(*Signer).Start()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/signer.go:70 +0x56
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.glob..func2.1()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/1_enck_handler_test.go:47 +0x331
  github.com/onsi/ginkgo/internal/leafnodes.(*runner).runSync()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/leafnodes/runner.go:113 +0xef
  github.com/onsi/ginkgo/internal/leafnodes.(*runner).run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/leafnodes/runner.go:64 +0x137
  github.com/onsi/ginkgo/internal/leafnodes.(*SetupNode).Run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/leafnodes/setup_nodes.go:15 +0x94
  github.com/onsi/ginkgo/internal/spec.(*Spec).runSample()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/spec/spec.go:193 +0x6c9
  github.com/onsi/ginkgo/internal/spec.(*Spec).Run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/spec/spec.go:138 +0x1a4
  github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).runSpec()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/specrunner/spec_runner.go:200 +0x16a
  github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).runSpecs()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/specrunner/spec_runner.go:170 +0x264
  github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).Run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/specrunner/spec_runner.go:66 +0x144
  github.com/onsi/ginkgo/internal/suite.(*Suite).Run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/suite/suite.go:62 +0x704
  github.com/onsi/ginkgo.RunSpecsWithCustomReporters()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/ginkgo_dsl.go:226 +0x2fa
  github.com/onsi/ginkgo.RunSpecs()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/ginkgo_dsl.go:207 +0x1d0
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.TestSigner()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/signer_test.go:37 +0xfb
  testing.tRunner()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:1595 +0x238
  testing.(*T).Run.func1()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:1648 +0x44

Goroutine 136 (running) created at:
  github.com/getamis/alice/types/message.(*MsgMain).Start()
      /home/skruglov/Projects/go/alice/types/message/msg_main.go:66 +0x19d
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.(*Signer).Start()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/signer.go:67 +0x55
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.glob..func2.1()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/1_enck_handler_test.go:47 +0x331
  github.com/onsi/ginkgo/internal/leafnodes.(*runner).runSync()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/leafnodes/runner.go:113 +0xef
  github.com/onsi/ginkgo/internal/leafnodes.(*runner).run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/leafnodes/runner.go:64 +0x137
  github.com/onsi/ginkgo/internal/leafnodes.(*SetupNode).Run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/leafnodes/setup_nodes.go:15 +0x94
  github.com/onsi/ginkgo/internal/spec.(*Spec).runSample()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/spec/spec.go:193 +0x6c9
  github.com/onsi/ginkgo/internal/spec.(*Spec).Run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/spec/spec.go:138 +0x1a4
  github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).runSpec()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/specrunner/spec_runner.go:200 +0x16a
  github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).runSpecs()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/specrunner/spec_runner.go:170 +0x264
  github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).Run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/specrunner/spec_runner.go:66 +0x144
  github.com/onsi/ginkgo/internal/suite.(*Suite).Run()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/internal/suite/suite.go:62 +0x704
  github.com/onsi/ginkgo.RunSpecsWithCustomReporters()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/ginkgo_dsl.go:226 +0x2fa
  github.com/onsi/ginkgo.RunSpecs()
      /home/skruglov/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/ginkgo_dsl.go:207 +0x1d0
  github.com/getamis/alice/crypto/tss/ecdsa/gg18/signer.TestSigner()
      /home/skruglov/Projects/go/alice/crypto/tss/ecdsa/gg18/signer/signer_test.go:37 +0xfb
  testing.tRunner()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:1595 +0x238
  testing.(*T).Run.func1()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:1648 +0x44

Goroutine 40 (running) created at:
  testing.(*T).Run()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:1648 +0x82a
  testing.runTests.func1()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:2054 +0x84
  testing.tRunner()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:1595 +0x238
  testing.runTests()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:2052 +0x896
  testing.(*M).Run()
      /home/skruglov/sdk/go1.21.0/src/testing/testing.go:1925 +0xb57
  main.main()
      _testmain.go:47 +0x2bd
==================
markya0616 commented 1 year ago

Got it. I will check it. Thanks a lot.

markya0616 commented 1 year ago

https://github.com/getamis/alice/pull/273 @papa-stiflera please help check again. Thanks a lot.