sta / sta/websocket-sharp

Clarify threading model

Open
#147 3 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

Hello,
I use the following code under Mono JIT compiler version 4.0.2, ubuntu 14.04:

public static void OnMessageReceived(object sender, EventArgs e)
{
Console.WriteLine ("thread pool id {0}",System.Threading.Thread.CurrentThread.ManagedThreadId);
/*
var evt = (WebSocketSharp.MessageEventArgs)e;
//We push the message to the ui thread to process all message in a single thread to avoid multithreading issues
Gtk.Application.Invoke(delegate {
ProcessMessage (evt.RawData);
});*/
}

Later in main :
ws = new WebSocket (uri);
ws.OnMessage += OnMessageReceived;

It seems I receive varying threadIds.
It is problematic because It means I lose the order of message that websockets (being over TCP) should guarantee.
It may happen that the first thread is executed after the second thread, which result in frames delivered in the wrong order.

Thank you

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 by tracing the WebSocket.OnMessage subscription and the OnMessageReceived callback shown in the issue, including the reported Thread.CurrentThread.ManagedThreadId behavior. Document which threading and message-ordering guarantees the library provides, and clarify whether callers must marshal processing to another thread.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.