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"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
@ -256,7 +257,7 @@ type Conn struct {
|
|||
handlePong func(string) error
|
||||
handlePing func(string) error
|
||||
handleClose func(int, string) error
|
||||
readErrCount int
|
||||
readErrCount int32
|
||||
messageReader *messageReader // the current low-level reader
|
||||
|
||||
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
|
||||
// tight loop on connection failure. To help application developers detect
|
||||
// this error, panic on repeated reads to the failed connection.
|
||||
c.readErrCount++
|
||||
if c.readErrCount >= 1000 {
|
||||
count := atomic.AddInt32(&c.readErrCount, 1)
|
||||
if count >= 1000 {
|
||||
panic("repeated read on failed websocket connection")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue