jgauffin / Griffin.Framework

Application framework for Business Applications
http://griffinframework.net
168 stars 63 forks source link

Null Exception (Thread Race Case?) #37

Closed Cimplex closed 9 years ago

Cimplex commented 9 years ago

In HttpMessageEncoder.cs:Line 144, I've noticed it throwing a really really weird error.

_message.Body.Dispose( ); was throwing the error. Apparently _message was null?!?! Even after your if statement... Threading is beyond me.

I fixed it by locking the whole class, but I don't know if that is the best way to do it.

public void Clear()
{
    lock ( this )
    {
        if ( _message != null && _message.Body != null )
            _message.Body.Dispose( );

        _bytesToSend = 0;
        _message = null;
        _isHeaderSent = false;
        _stream.SetLength( 0 );
    }
}

Either way, sweet project for sure! Thanks

jgauffin commented 9 years ago

Thanks for the report. I've corrected the problem using an internal lock.

I do agree that the problem is weird. According to the usages it isn't obvious why it happens. But it's probably that both the read and send completion ports detect the disconnect and tries to clean up.