Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix races #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix races #4

wants to merge 1 commit into from

Conversation

pikot
Copy link

@pikot pikot commented Jun 4, 2021

here is fixes for following races
1.

WARNING: DATA RACE
Write at 0x00c0022ae010 by goroutine 11:
  github.com/funny-falcon/go-iproto.(*Request).chainResponse()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:151 +0x2ee
  github.com/funny-falcon/go-iproto.(*Request).RespondFail()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:176 +0xa8
  github.com/funny-falcon/go-iproto.(*Request).Expire()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:52 +0x44
  github.com/funny-falcon/go-iproto.(*tHeap).loop()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/custom_timer.go:125 +0x2b8

Previous read at 0x00c0022ae010 by goroutine 46:
  github.com/funny-falcon/go-iproto/net/client/connection.(*Connection).writeLoop()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/net/client/connection/connection.go:295 +0x32b
WARNING: DATA RACE
Read at 0x00c00023659c by goroutine 56:
  github.com/funny-falcon/go-iproto.(*MultiRequest).Respond()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/wait_group.go:179 +0x3c4
  github.com/funny-falcon/go-iproto.(*Request).chainResponse()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:152 +0x294
  github.com/funny-falcon/go-iproto.(*Request).RespondBytes()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:172 +0xb0
  github.com/funny-falcon/go-iproto/net/client/connection.(*Connection).readLoop()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/net/client/connection/connection.go:220 +0x324

Previous write at 0x00c00023659c by goroutine 21:
  sync/atomic.StoreInt32()
      /usr/local/go/src/runtime/race_amd64.s:229 +0xb
  github.com/funny-falcon/go-iproto.(*MultiRequest).Request()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/wait_group.go:104 +0x315
  github.com/funny-falcon/go-iproto.(*MultiRequest).Send()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/wait_group.go:118 +0x71
WARNING: DATA RACE
Write at 0x00c006a80140 by goroutine 8:
  github.com/funny-falcon/go-iproto.(*Request).chainResponse()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:144 +0x1ca
  github.com/funny-falcon/go-iproto.(*Request).RespondFail()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:180 +0xa8
  github.com/funny-falcon/go-iproto.(*Request).Expire()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:52 +0x44
  github.com/funny-falcon/go-iproto.(*tHeap).loop()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/custom_timer.go:125 +0x2b8

Previous read at 0x00c006a80140 by goroutine 38:
  sync/atomic.LoadInt32()
      /usr/local/go/src/runtime/race_amd64.s:206 +0xb
  github.com/funny-falcon/go-iproto.(*Request).Performed()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/request.go:105 +0xcb
  github.com/funny-falcon/go-iproto.(*SimplePoint).Send()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/service.go:143 +0xe7
  github.com/funny-falcon/go-iproto/net/client.(*Server).Send()
      <autogenerated>:1 +0x51
  github.com/funny-falcon/go-iproto.(*MultiRequest).Send()
      /home/ivanov/go/src/github.com/funny-falcon/go-iproto/wait_group.go:124 +0x94

and some other

Copy link
Owner

@funny-falcon funny-falcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it is easier to completely rewrite this crap:-) I was too naive when I created it.

@@ -354,9 +354,9 @@ var rsL sync.Mutex

func ReaderFor(rt reflect.Type) (rd *TReader) {
rtid := reflect.ValueOf(rt).Pointer()
rsL.Lock()
defer rsL.Unlock()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should be fixed, but in other way.

@@ -228,9 +228,9 @@ var wsL sync.Mutex

func WriterFor(rt reflect.Type) (wr *TWriter) {
rtid := reflect.ValueOf(rt).Pointer()
wsL.Lock()
defer wsL.Unlock()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Either atomic.LoadPointer, or atomic.Value should be used.
Second is more preferred, i believe.

Or even sync.Map. It will be a bit slower on read, but cleanest choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants