I use renci.sshnet in a multi-threaded/multi-concurrent-connections environment. Under heavy testing we were seeing a leakage of around 1,500 event handles a minute. Under normal use, the leak was still evident; with heavy use causing the system to run out of resources and crash after weeks of continuous operations.
> See __[Proposed Fix] Chasing a serious Event Handle leak,... Part II__ and __[Proposed Fix] Chasing a serious Event Handle leak,... Part III__ for background
With the changes proposed for __[Proposed Fix] Chasing a serious Event Handle leak,... Part II__ there is one side effect that must be accounted for.
> Using Revision 28765 - Channel.cs - Line 619
```
private void OnChannelClose(object sender, MessageEventArgs<ChannelCloseMessage> e)
{
if (e.Message.LocalChannelNumber == this.LocalChannelNumber)
{
this.OnClose();
if (this._channelClosedWaitHandle!=null)
this._channelClosedWaitHandle.Set();
}
}
```
Since the Channel clean up can happen ahead of the eventhandler notification, a check is needed to prevent the dereferencing of a null member.
> See __[Proposed Fix] Chasing a serious Event Handle leak,... Part II__ and __[Proposed Fix] Chasing a serious Event Handle leak,... Part III__ for background
With the changes proposed for __[Proposed Fix] Chasing a serious Event Handle leak,... Part II__ there is one side effect that must be accounted for.
> Using Revision 28765 - Channel.cs - Line 619
```
private void OnChannelClose(object sender, MessageEventArgs<ChannelCloseMessage> e)
{
if (e.Message.LocalChannelNumber == this.LocalChannelNumber)
{
this.OnClose();
if (this._channelClosedWaitHandle!=null)
this._channelClosedWaitHandle.Set();
}
}
```
Since the Channel clean up can happen ahead of the eventhandler notification, a check is needed to prevent the dereferencing of a null member.