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

V1.5 SuperSocket.SocketEngine.SocketSession.OnSendingCompleted NullReferenceException #139

Open
wants to merge 62 commits into
base: master
Choose a base branch
from

Conversation

Arisoo
Copy link

@Arisoo Arisoo commented Mar 2, 2018

raised NullReferenceException on SuperSocket.SocketEngine.SocketSession.OnSendingCompleted(...)

but. my 1.5.1 SocketSession.cs and this repository's 1.5 SocketSession.cs was different.
so. maybe not bug on this repository's 1.5 version
yet. review this

    protected virtual void OnSendingCompleted(SendingQueue queue)
    {
        queue.Clear();
        m_SendingQueuePool.Push(queue);

        if (IsInClosingOrClosed)
        {
            RemoveStateFlag(SocketState.InSending);
            return;
        }

        var newQueue = m_SendingQueue;

        // A: raise System.NullReferenceException, as OnClose set m_SendingQueue into NULL
        if (newQueue.Count == 0)     
        {
            RemoveStateFlag(SocketState.InSending);

            if (newQueue.Count > 0)
            {
                StartSend(newQueue, newQueue.TrackID, true);
            }
        }
        else
        {
            StartSend(newQueue, newQueue.TrackID, false);
        }
    }

    // OnSendingComplete and OnClosed concurrently threaded on same SocketSession
    //    
    protected virtual void OnClosed(CloseReason reason)
    {
        AddStateFlag(SocketState.Closed);

        //Before changing m_SendingQueue, must check m_IsClosed
        while (true)
        {
            var sendingQueue = m_SendingQueue;

            if (sendingQueue == null)
                break;

            // B: I suppose above code raise NullReference whole OnSendingCompleted threading
            //There is no sending was started after the m_Closed ws set to 'true'
            if (Interlocked.CompareExchange(ref m_SendingQueue, null, sendingQueue) == sendingQueue)
            {
                sendingQueue.Clear();
                m_SendingQueuePool.Push(sendingQueue);
                break;
            }
        }

        var closedHandler = Closed;
        if (closedHandler != null)
        {
            closedHandler(this, reason);
        }
    }

That exception very rarely raise.
code A raise exception after code B was executed on concurrently.

Thanks~

=========================================
this problem solved at supersocket 1.6.7 ~~!!!
Must use supersocket version 1.6.7 later~
Thanks kerryjiang!

…hen create new receive filter in receive filter factory
Conflicts:

	SocketEngine/AsyncStreamSocketSession.cs
	SocketEngine/SuperSocket.SocketEngine.Net40.csproj
	SocketEngine/SuperSocket.SocketEngine.Net45.csproj
…for the ConfigurationCollection node in the SuperSocket custom configuration
@Arisoo Arisoo changed the title V1.5 V1.5 SuperSocket.SocketEngine.SocketSession.OnSendingCompleted NullReferenceException Mar 2, 2018
@kerryjiang
Copy link
Owner

Oh, it seems you send the PR to the wrong branch.

@kerryjiang
Copy link
Owner

Could you check if v1.6 has fixed this issue?

@Arisoo
Copy link
Author

Arisoo commented Mar 5, 2018

OK I'll try patch 1.6 ~
Thanks~

@Arisoo
Copy link
Author

Arisoo commented Aug 13, 2019

Hello again. it's so hacked.. late.. sorry~

I'll make some echo client and echo server
1 server process, 200 thread connection X 4
that problem solved !!! at 1.6.7 (stilll ok about 12 hours~)
(ref: that crash raised about 1 hour at 1.5.1)

so We must use 1.6.7 supersocket and superwebsocket 0.10.0

Thank you !!!

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

Successfully merging this pull request may close these issues.

None yet

2 participants