Skip to content

Safari workarounds - too long of JSON message, too frequently sent? #385

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

Closed
kirsle opened this issue Mar 30, 2023 · 3 comments
Closed

Safari workarounds - too long of JSON message, too frequently sent? #385

kirsle opened this issue Mar 30, 2023 · 3 comments

Comments

@kirsle
Copy link

kirsle commented Mar 30, 2023

I have a WebSocket chat room app that uses this module: https://github.com/kirsle/BareRTC and for a long time I am trying to figure out how to get Safari (on Mac OS Ventura, as well as iPhone/iPad) to like my app because currently disconnects happen a lot, to the point where users can't even get into the chat room to begin with. The WebSockets work OK on Chrome or Firefox on all device types tho (including Mac OS and Androids, but not iOS since all browsers there are Safari) -- it's only Safari on Ventura and iOS that doesn't like my chat room.

What I would see is Safari connects, sends its username, my server sends all the 'welcome messages' to various chat rooms, and this overwhelmed Safari somehow and it would promptly disconnect ("failed to read frame header: EOF" like it hung up the connection from the client side). I have seen in the Safari console it says: "protocol error" for the websocket, with no more useful info than that.

I did some poking today and some leads I found so far are one of two things:

  • If I removed all my welcome messages so that Safari doesn't receive too much upon connecting, it's able to log in and chat OK.
  • If "too long" of a message is sent, Safari will disconnect - I can do this by just copy/pasting a message until it's, idk 500 characters long - it's really not a huge threshold but once something that long comes back across the WebSocket, Safari hangs up immediately.
  • I also wonder if too rapid of messages trips it too - I've tried putting in timeouts and queues to only send a WS message once every 100ms-1s at most to Safari, but I haven't found if this makes an impact at all.

The most reliable way to disconnect Safari is just to send a "long" chat message; I think in my welcome messages, some of them listed some basic rules for my chat room, maybe only 500-1000 characters and that would disconnect Safari too. If I remove all welcome messages, Safari works until somebody says too much in chat and then it hangs up!

Has anyone encountered things like this and have ideas for workarounds? Unfortunately I own no Apple hardware to test on, I was able to get a Ventura VM going with OSX-KVM to at least see about desktop Safari.

@nhooyr
Copy link
Contributor

nhooyr commented Mar 31, 2023

Try disabling compression. See #218

@kirsle
Copy link
Author

kirsle commented Mar 31, 2023

This looks promising so far, thanks! From testing on Safari in a VM I'm not able to boot it off the chat so easily now and could even send a picture across (which my chat handles by echoing back an <img src="data:"> URL which woulda been a super easy way to kick Safari off before) - so far so good!

@nhooyr
Copy link
Contributor

nhooyr commented Mar 31, 2023

Awesome will close for now, eventually I'll get the dev branch into master where compression is disabled by default. #256

@nhooyr nhooyr closed this as completed Mar 31, 2023
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

2 participants