Client disconnects periodically when in channels with a moderate amount of traffic

Bug #862420 reported by Andy Jump
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
IRC.NET
Fix Committed
Medium
Alexander Regueiro

Bug Description

We're using IRC.Net in the SpikeLite IRC bot.

When running in ##csharp it periodically disconnects and reconnects.

This happens on both Linux with MONO and on Windows with .Net.

From the logs I can see that the bot appears to simply stop receiving data from the server and then disconnects a few minutes later.

At a guess this is because it's no longer receiving 'pings' and so send no 'pongs'.

Changed in ircdotnet:
importance: Undecided → Medium
assignee: nobody → Alex Regueiro (alexreg)
status: New → Confirmed
milestone: none → 0.4.2
Revision history for this message
Mat D (always-funny) wrote :

Because the activity on this project is very low I gathered the soruces and figured some bugs out, especially this one (which was not easy at all to fix...)

I was not really able to track this one down but I know what I changed to resove the issue:
I did change the CircularBufferStream in the following ways:
 public override long Length
        {
            get
            {
                var length = this.writePosition - this.readPosition;
                return length < 0 ? this.buffer.Length + length : length;
            }
        }

 public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotSupportedException();
        }

public override void Write(byte[] buffer, int offset, int count)
        {
            // Write block of bytes from given buffer into circular buffer, wrapping around when necessary.
            int writeCount;
            while ((writeCount = Math.Min(count, (int)(this.buffer.Length - this.writePosition))) > 0)
            {
                var oldWritePosition = this.writePosition;
                var newWritePosition = (this.writePosition + writeCount) % this.buffer.Length;
                if (newWritePosition > readPosition && oldWritePosition < readPosition)
                {
                    throw new InternalBufferOverflowException("Der CircularBuffer wurde überlaufen!");
                }
                System.Buffer.BlockCopy(buffer, offset, this.buffer, (int)this.writePosition, writeCount);
                this.writePosition = newWritePosition;

                offset += writeCount;
                count -= writeCount; //writeCount <= count => now is count >=0
            }
        }

 public override int Read(byte[] buffer, int offset, int count)
        {
            // Read block of bytes from circular buffer, wrapping around when necessary.
            int totalReadCount = 0;
            int readCount;
            count = Math.Min(buffer.Length - offset, count);
            while ((readCount = Math.Min(count, (int)(Length))) > 0)
            {
                if (readCount > this.buffer.Length - readPosition)
                {
                    readCount = (int)(this.buffer.Length - readPosition);
                }
                System.Buffer.BlockCopy(this.buffer, (int)this.readPosition, buffer, offset, readCount);
                this.readPosition = (this.readPosition + readCount) % this.buffer.Length;
                offset += readCount;
                count = Math.Min(buffer.Length - offset, count);
                totalReadCount += readCount;
            }
            return totalReadCount;
        }

I think the problem occured on some special cases at the end of the CircularBuffer which were not handled correctly.
( but I'm not 100% sure )
Added the patched file as Attachment (not sure if it will compile in the current version on this site)

It's not possible for me to reupload my complete implementation as i changed lots of Logging to be able to track this down...

Hope this helps!
reddragon

Revision history for this message
Alexander Regueiro (alexreg) wrote :
Changed in ircdotnet:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.