sta / sta/websocket-sharp

Closing a WebSocketBehavior and opening it again

Open
#144 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

When a service derived from WebSocketBehavior is closed the base class does not set _websocket to null. Then when a client tries to reconnect it fails because the base class thinks the session is already started.
I have this workaround in place in the derived class:

    protected override void OnClose(CloseEventArgs e)
        {
        // ...
        var base_websocket = typeof(MyService).BaseType
                .GetField("_websocket", BindingFlags.Instance | BindingFlags.NonPublic);
        if (base_websocket != null)
            base_websocket.SetValue(this, null);
        }

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

Locate WebSocketBehavior and its OnClose lifecycle, then inspect how _websocket is initialized and checked when a client reconnects. Confirm the close-and-reopen behavior with an existing test or reproduction if available, and verify that the derived-class reflection workaround is no longer needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.