diff --git a/conn.go b/conn.go index 3d7d574efcd29b34c65fe309399d7f152b259f54..2d0339e4ae3ef08b1a7bfa8065106ebff228a40c 100644 --- a/conn.go +++ b/conn.go @@ -70,7 +70,8 @@ type Conn struct { activeReader *messageReader // readFrameLock is acquired to read from bw. readFrameLock chan struct{} - readClosed int64 + // Not int32 because of https://github.com/nhooyr/websocket/issues/153 + readClosed int32 readHeaderBuf []byte controlPayloadBuf []byte @@ -341,7 +342,7 @@ func (c *Conn) handleControl(ctx context.Context, h header) error { // See https://github.com/nhooyr/websocket/issues/87#issue-451703332 // Most users should not need this. func (c *Conn) Reader(ctx context.Context) (MessageType, io.Reader, error) { - if atomic.LoadInt64(&c.readClosed) == 1 { + if atomic.LoadInt32(&c.readClosed) == 1 { return 0, nil, fmt.Errorf("websocket connection read closed") } diff --git a/conn_common.go b/conn_common.go index ae0fe55498610b3508dd175d034d535436afcb89..9a4f904338ca90f25123cf13edba3d1de388a869 100644 --- a/conn_common.go +++ b/conn_common.go @@ -178,7 +178,7 @@ func (c *netConn) SetReadDeadline(t time.Time) error { // Use this when you do not want to read data messages from the connection anymore but will // want to write messages to it. func (c *Conn) CloseRead(ctx context.Context) context.Context { - atomic.StoreInt64(&c.readClosed, 1) + atomic.StoreInt32(&c.readClosed, 1) ctx, cancel := context.WithCancel(ctx) go func() { diff --git a/websocket_js.go b/websocket_js.go index 3822797b3f953d0a449d2ae0558ead13f2d3a270..dcb02061ed9396a188262ee7b806092584568707 100644 --- a/websocket_js.go +++ b/websocket_js.go @@ -89,7 +89,7 @@ func (c *Conn) closeWithInternal() { // Read attempts to read a message from the connection. // The maximum time spent waiting is bounded by the context. func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) { - if atomic.LoadInt64(&c.readClosed) == 1 { + if atomic.LoadInt32(&c.readClosed) == 1 { return 0, nil, fmt.Errorf("websocket connection read closed") }