Infinite loop during event serialization

Feb 6, 2013 at 12:40 PM
Edited Feb 6, 2013 at 12:50 PM
Hi, keithh.
We noticed it’s very slow to publish some very large event. After debugging into the code, we found the thread entered into infinite loop during event serialization, can you help check whether it’s a bug:
       private void AppendBytes(byte[] src, int offset, int length)
        {
            if ((position + length) > buffer.Length)
            {
                int newLength = buffer.Length;

                while( newLength < (position + length) ) //Compare the value
                {
                    if ((int.MaxValue / 2) > buffer.Length)
                    {
                        newLength = buffer.Length * 2;  // Give a bigger value?
                    }
Seem if newLength is not bigger than position + length after buffer.Length * 2 is given as the new value, the while loop never has the chance to reach to the end. Can you suggest how to make a prefect fix on this? For now, we change the code as below; however, we are not sure about this change, please help。
        {
            if ((position + length) > buffer.Length)
            {
                int newLength = buffer.Length;

                while( newLength < (position + length) )
                {
                    if ((int.MaxValue / 2) > newLength)
                    {
                        newLength = newLength * 2; 
                    }
Thanks
Coordinator
Feb 6, 2013 at 2:33 PM
Your fix looks correct, I'll change my code to match. If you're going to be sending large events, just make sure the eventQueueSize setting in the config file is multiple times your largest event size.