Skip to content

Exception in ChannelSession ReleaseSemaphore #400

Closed
@fabricedupre

Description

@fabricedupre

Hello,

I am using latest stable release 2016.1.0 on Windows 10 with Visual Studio 2017 within a desktop application.

ReleaseSemaphore sometimes throws a SystemNullReference exception. To circumvent that issue I had to modify the function to:

    private void ReleaseSemaphore()
    {
        if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 0, 1) == 1)
        {
                SemaphoreLight sem = SessionSemaphore;

                if (sem != null)
                    sem.Release();
                else
                    System.Diagnostics.Trace.WriteLine("*** SessionSemaphore NULL");
        }
    }

Digging a little bit, I found that in fact the issue came from Channel SessionSemaphore property. I also had to change it a little bit as below:

    protected SemaphoreLight SessionSemaphore
    {
        get
        {
                ISession s = _session;

                if (s != null)
                    return s.SessionSemaphore;
            
                System.Diagnostics.Trace.WriteLine("*** session NULL");
                return null;
        }
    }

Running my app with those changes, I sometimes get the below trace output, but no more exception:
*** session NULL
*** SessionSemaphore NULL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions