mirror of https://github.com/gorilla/websocket.git
Fix a data race related to readErrCount
This commit is contained in:
parent
292fd08b25
commit
50391a1a84
7
conn.go
7
conn.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
@ -256,7 +257,7 @@ type Conn struct {
|
||||||
handlePong func(string) error
|
handlePong func(string) error
|
||||||
handlePing func(string) error
|
handlePing func(string) error
|
||||||
handleClose func(int, string) error
|
handleClose func(int, string) error
|
||||||
readErrCount int
|
readErrCount int32
|
||||||
messageReader *messageReader // the current low-level reader
|
messageReader *messageReader // the current low-level reader
|
||||||
|
|
||||||
readDecompress bool // whether last read frame had RSV1 set
|
readDecompress bool // whether last read frame had RSV1 set
|
||||||
|
@ -955,8 +956,8 @@ func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
|
||||||
// Applications that do handle the error returned from this method spin in
|
// Applications that do handle the error returned from this method spin in
|
||||||
// tight loop on connection failure. To help application developers detect
|
// tight loop on connection failure. To help application developers detect
|
||||||
// this error, panic on repeated reads to the failed connection.
|
// this error, panic on repeated reads to the failed connection.
|
||||||
c.readErrCount++
|
count := atomic.AddInt32(&c.readErrCount, 1)
|
||||||
if c.readErrCount >= 1000 {
|
if count >= 1000 {
|
||||||
panic("repeated read on failed websocket connection")
|
panic("repeated read on failed websocket connection")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue