sta / sta/websocket-sharp

Websocket connection doesn't work after reload on OSX Web Player

Open
#51 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

In our application, we're connecting to a server via web sockets to listen for new data. Everything works fine on the desktop builds, and the web player on windows, and on OSX with a freshly-opened browser. After a browser reload, or closing and re-opening a tab, we get errors receiving websocket messages. It looks like we're hitting a known issue with Unity and the various Async IO methods in the web player, where Async processes don't get closed properly when the player is stopped.

Here is an informative forum post describing the issue. In this case the resolution was to abandon the Async methods and spawn a separate thread manually that does blocking reads.
http://forum.unity3d.com/threads/socket-wont-stay-connected-after-reloading-webplayer.102776/

In our case specifically the exception was "An exception has occurred while receiving a message." That error was coming from ParseAsync which was throwing the exception "The header part of a frame cannot be read from the data source." because header.Length was zero. This seems to match up with the error reported above, where async reads were returning zero bytes after a reload.

As this seems to be an open and long-standing issue in Unity, would it be hard to refactor out the Async methods? I'm not sure if there's another workaround to get things working in OSX Web Player after a refresh (if you have one we're all ears).

Thanks.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ParseAsync and trace the asynchronous receive path described in the issue, then reproduce the failure by reloading or reopening an OSX Web Player tab. Done means websocket messages can be received after reload without the zero-length-header exception, with the chosen workaround verified against this scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
networking
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.