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

Websocket error on Safari #169

Open
gabridego opened this issue Apr 18, 2023 · 4 comments
Open

Websocket error on Safari #169

gabridego opened this issue Apr 18, 2023 · 4 comments

Comments

@gabridego
Copy link

gabridego commented Apr 18, 2023

I am developing a WebRTC service which uses your library for the signalling phase. Everything works well on Chrome, Firefox and Android, but I am experiencing an error on Safari (macOS Ventura 13.3) and iOS:

[Error] WebSocket connection to 'wss://myapp.com/ws' failed: The operation couldn’t be completed. Socket is not connected

Anyway, it works on Safari when disabling the experimental feature 'NSURLSession WebSocket', which makes me suspect of a possible issue with WebSocket compression. Some related issues:

Is there any configuration I can use to make my websocket application work on Safari and iOS as well? Thank you!

@cristaloleg
Copy link
Collaborator

Hi, thank you for the detailed issue. I haven't met problems so far, so I cannot share any meaningful configuration.

I will try to debug it but no idea will I find something or not.

@gabridego
Copy link
Author

Hi, thank you for your quick reply!
I can reproduce the issue with a very minimal example:

package main

import (
	"net/http"

	"github.com/gobwas/ws"
	"github.com/gobwas/ws/wsutil"
)

func main() {
	http.ListenAndServe(":9090", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		conn, _, _, _ := ws.UpgradeHTTP(r, w)
		defer conn.Close()

		wsutil.WriteServerText(conn, []byte("ciao"))
	}))
}

On Safari console:

ws = new WebSocket("ws://127.0.0.1:9090")
ws.onmessage = (msg) => console.log(msg.data)

With NSURLSession WebSocket enabled, it prints ciao and then gives the error. With the function disabled, just the message with no error.

Am I doing anything wrong? Thanks!

@sudhakar
Copy link

More discussion about this with possible workarounds in uNetworking/uWebSockets#1347. As per the thread only "Safari 15.0-15.3" is affected and looks like 15.4 onwards works fine

Some workarounds discussed there are,

  1. Disable compression if useragent is "Safari 15.0-15.3"
  2. If compression is needed, have sufficient buffer size, so that message is not fragmented and hence wont trigger this bug in broken safari (Safari (macOS 12, iOS 15) and compression is broken uNetworking/uWebSockets#1347 (comment))

If anybody gets to test any of these workarounds, please report here

@FZambia
Copy link

FZambia commented Apr 20, 2023

The example shown by @gabridego does not use compression. Also, I tested it on Safari 16.1 - and the error is still there. So I think those are two different Safari problems.

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

No branches or pull requests

4 participants