Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] error: RSV1 set, bad opcode 7, bad MASK #886

Closed
1 task done
jiangbo202 opened this issue Jan 4, 2024 · 10 comments
Closed
1 task done

[question] error: RSV1 set, bad opcode 7, bad MASK #886

jiangbo202 opened this issue Jan 4, 2024 · 10 comments
Labels

Comments

@jiangbo202
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I will follow this example( https://github.com/gorilla/websocket/tree/main/examples/chat )Start the machine locally, then open it through Google Chrome, enter "test" and click send, but it will directly display: Connection closed.
By adding the print on line 70 of the client.go file, log Println ("xxxX:", err)
Result: websocket: RSV1 set, bad opcode 7, bad MASK

image
image

I checked #797 , but it worked fine after restarting the computer. However, I have restarted the computer multiple times and it still hasn't worked

I tried other people's computers, and the systems such as Win and Mac Intel chips were all working properly. I also closed all proxy software on my computer, but it didn't work

The error is happening on a MacBook Pro 2021 M1 Pro.
go version: go version go1.20.6 darwin/arm64

Expected Behavior

No response

Steps To Reproduce

No response

Anything else?

No response

@jiangbo202 jiangbo202 added the bug label Jan 4, 2024
@canselcik
Copy link

Similarly on occasion I am getting:

RSV1 set, RSV2 set, bad opcode 15

panic: runtime error: slice bounds out of range [:4643] with capacity 4096
goroutine 645701 [running]:
 bufio.(*Reader).Read(0xc021bbe0c0, {0xc018005ab4?, 0x4c?, 0x1500?})
         /root/go/src/bufio/bufio.go:257 +0x2d0
 github.com/gorilla/websocket.(*messageReader).Read(0xc000186d50, {0xc018005ab4, 0x4c, 0x4c})
        /root/serversrc/server/vendor/github.com/gorilla/websocket/conn.go:1075 +0x1c5
 io.ReadAll({0x7f3f11630f20, 0xc000186d50})
         /root/go/src/io/io.go:704 +0x7e
 github.com/gorilla/websocket.(*Conn).ReadMessage(0x7f3f71fd9a68?)
/root/serversrc/server/vendor/github.com/gorilla/websocket/conn.go:1124 +0x3b

@canselcik
Copy link

canselcik commented Feb 13, 2024

Similar error, happened today.
RSV2 set, RSV3 set, FIN not set on control

panic: runtime error: slice bounds out of range [:5472] with capacity 4096
goroutine 2743107 [running]:
 bufio.(*Reader).Read(0xc021f567e0, {0xc000293a04?, 0x4fc?, 0x1000?})
         /root/go/src/bufio/bufio.go:257 +0x2d0
 github.com/gorilla/websocket.(*messageReader).Read(0xc00013b150, {0xc000293a04, 0x4fc, 0x4fc})
         /root/serversrc/server/vendor/github.com/gorilla/websocket/conn.go:1075 +0x1c5
 io.ReadAll({0x7fa3e8131498, 0xc00013b150})
         /root/go/src/io/io.go:704 +0x7e
 github.com/gorilla/websocket.(*Conn).ReadMessage(0xc0179c70e0?)
         /root/serversrc/server/vendor/github.com/gorilla/websocket/conn.go:1124 +0x3b

@canselcik
Copy link

canselcik commented Feb 13, 2024

Thank you @GreenMarmot. I am aware of that and both read and writes are guarded with mutexes. I have also ran the application with the go race detector and haven't hit any results pointing in that direction.

But will continue to explore that angle.

@Nasar165
Copy link

Nasar165 commented Mar 18, 2024

Hi where any one able to find any solution to the issue I'm getting a similar error on my M1 machine I've tried running in docker, VM (UTM) Ubuntu server (ARM version) without any success, I've also tried to to reset the MAC to factory without any success. This specific issue seems isolated to M1 since the code works without any issue on m2 also tried using on my AMD cpu and no issues.

Failing Environment

MacBook Pro Apple M1 Sonoma 14.4 16GB Ram

  • Go version 1.22.1 (ARM)
  • Go version 1.22.1 (AMD64) (Rosseta)
  • Docker (ARM)
  • Ubuntu 22 server version (ARM) (UTM VM)
  • Chrome 122.0.6261.129 (Official Build) (arm64)
  • Safari 17.4

Successful environment

  • AMD CPU
  • INTEL CPU
  • MacBook Pro Apple M2 Sonoma 14.4 16GB Ram

Error

RSV1 set, bad opcode 7, bad Mask

  • Frametype is set to 7 which crashes in the select loop

Hint

  • if Compression is enabled RSV1 disappears
  • Attempted other Golang packages fashhttp ,ws all crash
  • Python works without any issues
  • no proxies installed
  • able to send message from server to client
  • only crash when client send to server

@Nasar165
Copy link

Nasar165 commented Mar 19, 2024

Solution

For those who get the following error using Apple MacBook: RSV1 set, bad opcode 7, bad Mask when trying to connect from any client within the system can try and disable Content & Privacy that can be found in settings > Screen time > Content & Privacy and then disable Content & Privacy. This solved my issue on my MacBook M1 running Sonoma 14.4.

ps: do disable share across device before disabling to not disable on other devices and then restart the laptop and web filter service should be gone.

Command to view services

sudo lsof -i -P | grep LISTEN

Possible reason

Possible reason is that the WebFilter service was filtering the payload modifying the Frame leading to malformed frames unaware if this is intentional of a bug from apple.

@jiangbo202
Copy link
Author

Thank you @Nasar165 , using your method also solved my problem

@Nasar165
Copy link

Happy to be of help @jiangbo202

@tubzby
Copy link

tubzby commented Apr 1, 2024

Got a similar panic, is it concurrent read your case @canselcik ?

 level=error msg="read error: websocket: RSV2 set, RSV3 set, FIN not set on control" file=signal/ws.go line=87 mo
 panic: runtime error: slice bounds out of range [:4200] with capacity 4096
 goroutine 10353098 [running]:
 bufio.(*Reader).Read(0x40015a7740, {0x4000e15fc8?, 
         /usr/local/go/src/bufio/bufio.go:250 +0x334
 github.com/gorilla/websocket.(*messageReader).Read
         /go/pkg/mod/github.com/gorilla/websocket@v1.5.
 io.ReadAll({0x7f63384600, 0x4002dfa1e0})
         /usr/local/go/src/io/io.go:701 +0xe4
 io/ioutil.ReadAll(...)
         /usr/local/go/src/io/ioutil/ioutil.go:27
 github.com/gorilla/websocket.(*Conn).ReadMessage
         /go/pkg/mod/github.com/gorilla/websocket@v1.5.
 gdcx.com/rtsp2webrtc/signal.(*wsSignal).connectLoop.
         /usr/src/myapp/signal/ws.go:85 +0xc0
 created by gdcx.com/rtsp2webrtc/signal.(*wsSignal).
         /usr/src/myapp/signal/ws.go:81 +0x274
service: Main process exited, code=exited, status=2/
service: Failed with result 'exit-code'.

My logic is quite simple:

for shouldConnect {
    for {
           connect until success
    }

   go func() {
     for {
         // read until error
         // panic here
          ws.ReadMessage()
          send to channel
     }
   }()

  // read from channel
  // or wait a specific amount of time, send `KeepAlive` to peer.
  for {
  }
}

In my case, read/write might be concurrent, but there's only one reader for a connection.

@canselcik
Copy link

canselcik commented Apr 1, 2024

Yes, @tubzby, it was. @GreenMarmot was spot on.

In your case I believe if you changed your code to do something to the spirit of the following, the issue will be addressed:

go func(ws *websocket.Conn) {
     for {
         // read until error
         // panic here
          ws.ReadMessage()
          send to channel
     }
   }(ws)

Instead of having your goroutine capture ws from its scope, pass it a parameter.

@tubzby
Copy link

tubzby commented Apr 1, 2024

@canselcik Thanks for your suggestion, will try that, I'm convinced this was the root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants