Comments (10)
Unfortunately I can't right now, but I will try to dig up more information and possibly even a reproduction test case.
from go-sse.
There are many things wrong, I'm working on a proper fix for the entire lib, but it will take a bit more time.
from go-sse.
These two data races seem rare and hard to trigger.
from go-sse.
Could you share some of your code?
from go-sse.
Don't know if this is relevant, but I've experienced some of this:
WARNING: DATA RACE
Write at 0x00c000284018 by goroutine 13:
github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
/home/cw/go/pkg/mod/github.com/alexandrevicenzi/[email protected]/channel.go:26 +0x8c
github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
/home/cw/go/pkg/mod/github.com/alexandrevicenzi/[email protected]/sse.go:119 +0x21b
I was able to fix it by just wrapping a Lock() and Unlock() around that c.lastEventID = message.id in channel.go:26 like this:
// SendMessage broadcast a message to all clients in a channel.
func (c *Channel) SendMessage(message *Message) {
c.mu.Lock() // <-- new
c.lastEventID = message.id
c.mu.Unlock() // <-- new
c.mu.RLock()
for c, open := range c.clients {
if open {
c.send <- message
}
}
c.mu.RUnlock()
}
At least in initial testing, it resolves the data race.
from go-sse.
In my case, it was very reproducible and this instantly fixed it.
from go-sse.
Spoke too soon -- have another on sse.go:96:
msg.retry = s.options.RetryInterval
from go-sse.
Yes, it can happen anywhere, the lib is using goroutines where it's not needed and for that needs locks everywhere. The way to fix it is by removing most and leave only when required.
from go-sse.
Can reproduce issue with set last lastEventID. My pattern of usage send multiple messages of different time to the same client like multiple topics subscriptions. It easy appears in tests, due absence of significant delay.
Race log is follow:
WARNING: DATA RACE
Write at 0x00c000436258 by goroutine 49:
github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
/vendor/github.com/alexandrevicenzi/go-sse/channel.go:26 +0x8c
github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
/vendor/github.com/alexandrevicenzi/go-sse/sse.go:116 +0x21b
/rest/handlers.(*eventsHandler).trackFlow.func1()
/rest/handlers/events.go:137 +0x124
Previous write at 0x00c000436258 by goroutine 48:
github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
/vendor/github.com/alexandrevicenzi/go-sse/channel.go:26 +0x8c
github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
/vendor/github.com/alexandrevicenzi/go-sse/sse.go:116 +0x21b
/rest/handlers.(*eventsHandler).trackFlow.func1()
/rest/handlers/events.go:137 +0x124
and the patch is exactly the same:
diff --git a/go/vendor/github.com/alexandrevicenzi/go-sse/channel.go b/go/vendor/github.com/alexandrevicenzi/go-sse/channel.go
index 82be4197..c66f948e 100644
--- a/go/vendor/github.com/alexandrevicenzi/go-sse/channel.go
+++ b/go/vendor/github.com/alexandrevicenzi/go-sse/channel.go
@@ -23,7 +23,9 @@ func newChannel(name string) *Channel {
// SendMessage broadcast a message to all clients in a channel.
func (c *Channel) SendMessage(message *Message) {
+ c.mu.Lock()
c.lastEventID = message.id
+ c.mu.Unlock()
c.mu.RLock()
from go-sse.
https://gist.github.com/iscander/9a144528e563dc5969346d5e0b61cd4f yet another sample which rises same data race but as a part of HTTPHandler
from go-sse.
Related Issues (16)
- Conditional logging HOT 3
- Javascript client is receiving messages by batch HOT 1
- obsolete CloseNotifier() HOT 1
- Using with Echo? HOT 3
- "welcome" event HOT 11
- Add HTTP/2 support HOT 1
- Send SSE data only when it received POST method HOT 1
- Multiple open tabs communicating HOT 3
- Last Event ID HOT 3
- panic on graceful shutdown HOT 4
- gofmt your code HOT 2
- Does not work with gzip.DefaultCompression
- Message retry always 0?
- Not safe for concurrent use HOT 3
- *middleware.compressResponseWriter is not http.CloseNotifier: HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-sse.