==================
WARNING: DATA RACE
Write by goroutine 22:
runtime.copy()
/usr/local/go/src/pkg/runtime/slice.c:120 +0x0
bufio.(*Writer).Write()
/usr/local/go/src/pkg/bufio/bufio.go:538 +0x40a
net/http.(*response).write()
/usr/local/go/src/pkg/net/http/server.go:986 +0x32c
net/http.(*response).Write()
/usr/local/go/src/pkg/net/http/server.go:958 +0x88
...
github.com/fumin/webutil.func·001()
/var/lib/openshift/key/app-root/data/build/src/github.com/fumin/webutil/sse.go:55 +0x160
Previous read by goroutine 21:
runtime.copy()
/usr/local/go/src/pkg/runtime/slice.c:120 +0x0
bufio.(*Writer).Write()
/usr/local/go/src/pkg/bufio/bufio.go:538 +0x40a
net/http.(*chunkWriter).Write()
/usr/local/go/src/pkg/net/http/server.go:259 +0x3e5
bufio.(*Writer).flush()
/usr/local/go/src/pkg/bufio/bufio.go:494 +0x15a
bufio.(*Writer).Flush()
/usr/local/go/src/pkg/bufio/bufio.go:483 +0x34
net/http.(*response).Flush()
/usr/local/go/src/pkg/net/http/server.go:1023 +0x7f
I wonder is it a reasonable requirement for a http.(*response) to support concurrent writes? If not, am I supposed to implement additional synchronizations using something like a sync.Mutex? If so, where should I add the mutex, perhaps in the form of:
// ConcurrentResponseWriter is too verbose, is there a better name for it?
type ConcurrentResponseWriter struct {
sync.Mutex
*http.ResponseWriter
}
func (w * ConcurrentResponseWriter) Write(b []byte) error {
w.Lock()
defer w.Unlock()
return w.Write(b)
}
func (w * ConcurrentResponseWriter) Flush() {
w.Lock()
defer w.Unlock()
w.Flush()
}
looks a bit too verbose, and too much trouble.
Sticking to one goroutine per connection is the easiest way to handle connections in my experience. You could use a select along with a time.Ticker (or something like that) in a loop in your handle function to implement a heartbeat.
I wonder is it a reasonable requirement for a http.(*response) to support concurrent writes? If not, am I supposed to implement additional synchronizations using something like a sync.Mutex? If so, where should I add the mutex, perhaps in the form of:
// ConcurrentResponseWriter is too verbose, is there a better name for it?
type ConcurrentResponseWriter struct {
sync.Mutex
*http.ResponseWriter
}
func (w * ConcurrentResponseWriter) Write(b []byte) error {
w.Lock()
defer w.Unlock()
return w.Write(b)
}
func (w * ConcurrentResponseWriter) Flush() {
w.Lock()
defer w.Unlock()
w.Flush()
}
looks a bit too verbose, and too much trouble.
func (w * ConcurrentResponseWriter) Write(b []byte) error {
w.Lock()
defer w.Unlock()
return w.Write(b)
}
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/oYwNE68P68M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.