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: data race in send message #3

Merged
merged 2 commits into from
Nov 22, 2022
Merged

Conversation

isdzulqor
Copy link

@isdzulqor isdzulqor commented Nov 22, 2022

Summary

The issue was initially pointed out and solved here

This PR cherry-picked two commits from it.

  1. 562d884930c5f545f01e5b2251fbb159a5355c25
  2. 58741aa877bcb591c8e0e68b083d04d7c673a4b5

Thank you @iscander for the outstanding contribution to this 🎉

The usage pattern: Imagine  we have a client which subsribed to multiple topics
inside one connection. It track changes of specific items state by their ID
as example.

The test is passing in general case. But run it with race detection option and
it fails due data race condition detected.

==================
WARNING: DATA RACE
Write at 0x00c0000120d8 by goroutine 39:
  github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
      /Users/iscander/projects/go-sse/channel.go:26 +0x8c
  github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
      /Users/iscander/projects/go-sse/sse.go:116 +0x21b
  github.com/alexandrevicenzi/go-sse.TestMultipleTopics.func2()
      /Users/iscander/projects/go-sse/sse_test.go:135 +0xce

Previous write at 0x00c0000120d8 by goroutine 38:
  github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
      /Users/iscander/projects/go-sse/channel.go:26 +0x8c
  github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
      /Users/iscander/projects/go-sse/sse.go:116 +0x21b
  github.com/alexandrevicenzi/go-sse.TestMultipleTopics.func2()
      /Users/iscander/projects/go-sse/sse_test.go:135 +0xce

Goroutine 39 (running) created at:
  github.com/alexandrevicenzi/go-sse.TestMultipleTopics()
      /Users/iscander/projects/go-sse/sse_test.go:132 +0x735
  testing.tRunner()
      /usr/local/Cellar/go/1.16.3/libexec/src/testing/testing.go:1193 +0x202

Goroutine 38 (running) created at:
  github.com/alexandrevicenzi/go-sse.TestMultipleTopics()
      /Users/iscander/projects/go-sse/sse_test.go:132 +0x735
  testing.tRunner()
      /usr/local/Cellar/go/1.16.3/libexec/src/testing/testing.go:1193 +0x202
Protect the option by wrappring into a mutex. The datarace is gone.
It closes alexandrevicenzi#18
Copy link
Collaborator

@riandyrn riandyrn left a comment

Choose a reason for hiding this comment

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

LGTM. Great work, @isdzulqor! 🎉🎉🎉

Thanks for your contribution, @iscander!

@riandyrn riandyrn merged commit d67a98f into master Nov 22, 2022
@riandyrn riandyrn deleted the fix/data-race-in-send-msg branch November 22, 2022 19:24
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.

3 participants