Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#73 Index was outside the bounds of the array.

v1.0_(example)
pending
Doug Day
5
2012-10-26
2011-11-16
Martijn
No

Hi Doug!

Great work on the library. We use it to encode schedule information, where users can subscribe to an online iCalendar feed. About 5000 requests a day are handled without any problems.

However; every few weeks the error "Index was outside the bounds of the array" is thrown, influencing hundrerds of users. (check the stacktrace).

Stacktrace:
at System.Collections.Generic.Stack`1.Push(T item)
at DDay.iCal.Serialization.SerializationContext.Push(Object item)
at DDay.iCal.Serialization.iCalendar.PropertySerializer.SerializeToString(Object obj)
at DDay.iCal.Serialization.iCalendar.ComponentSerializer.SerializeToString(Object obj)
at DDay.iCal.Serialization.iCalendar.iCalendarSerializer.SerializeToString(Object obj)

When I run the project in the sandbox, connecting to the same data, everything works fine. So unfortunately I can't reproduce it :( After I give IIS a cycle, the feed starts working okay again.

Is anything caused by a problem of encoding on my end? Is it a memory issue?

And last, but not least: Is this something that might have been fixed in a new version??? (I have the 8-10-2010 bin... this is my latest, right?)

Discussion

  • Doug Day
    Doug Day
    2012-05-22

    Thanks for reporting this issue; however, I can't reproduce. Can you give any additional information?

    Regards,
    -Doug

     
  • Adam
    Adam
    2012-08-02

    HI, just wanted to let you know that we are also seeing this behaviour when our system is under high load. I do not have a repro yet. Note we have to do an IISRESET to fix the issue, after the problem occurs, the issue does not go away even if load reduces.

     
  • Doug Day
    Doug Day
    2012-08-04

    Just a thought - grab a memory snapshot if this occurs again. It's possible there may be a memory leak issue here, though I have memory profiled it before to ensure there are not any leaks. That said, it's worth a shot to make sure there aren't any major issues going on.

    -Doug

     
  • Adam Hamilton
    Adam Hamilton
    2012-08-15

    Wanted to let you know that I have experienced this bug under load as well. It appears to be a concurrency issue, as locking around the serialization call so that only one ASP.NET page can serialize at once eliminates the problem.

    While I don't have specific information about this library, I have experienced this exact problem with a different library. The error turned out to be caused by a use of a collection in a non-thread-safe way. When you use a collection without the proper locking when adding items, missed updates can cause the collection's Count to diverge from the actual number of items in the collection. Then, when you loop over the collection (based on the count), you get "index out of bounds" because the count itself is incorrect and you are attempting to correctly access an item that doesn't exist because the collection has bad information.

    So, if I was looking for this issue, I'd look at static collections and things like that. It might not be a bug in your code that causes it to access a position that doesn't exist, but rather a thread safety issue that causes the collection to claim items exist that then turn out not to.

    Hope that helps! It took a me long time to figure that one out when I encountered it. If I can find any more information that's specific to the library itself, I'll let you know.

     
  • Adam
    Adam
    2012-08-15

    Hi, I have a repro, what follows is a unit test that spins up 1800 threads, this can cause the error to occur. I had to turn on Debug-Exceptions-Break when CLR exception is thrown, and then run unit test in debug mode.

        [Test]
        public void MultiThreadedCalendarTest()
        {
            Thread[] threads = new Thread[1800];
    
            for (int i = 0; i < threads.Length;i++ )
            {
                threads[i] = new Thread(DoSomeWork);
            }
    
            foreach (Thread thread in threads)
            {
                thread.Start();
            }
    
            foreach (Thread thread in threads)
            {
                thread.Join();
            }
        }
    
        private static void DoSomeWork()
        {
            var evt = GetEvent(unusualCal);
            int result = -1;
    
            if (evt != null)
            {
                result = evt.Priority;
                System.Diagnostics.Debug.WriteLine(result);
            }            
        }
    
        private static DDay.iCal.Event GetEvent(string value)
        {
            DDay.iCal.Event evt = null;
            DDay.iCal.iCalendar iCal = null;
            try
            {
                iCal = DDay.iCal.iCalendar.LoadFromStream<DDay.iCal.iCalendar>(new StringReader(value))[0] as DDay.iCal.iCalendar;
            }
            catch (Exception ex)
            {
                throw new ArgumentException(
                    string.Format("{0} is not a valid iCalendar rfc-2445 format", value), ex);
            }
            if (iCal.Events.Count != 0)
                evt = iCal.Events[0] as Event;
    
            return evt;
        }
    
        private static string unusualCal =
    

    @"BEGIN:VCALENDAR
    VERSION:2.0
    PRODID://Company//NOSGML Product//EN
    BEGIN:VEVENT
    DTSTAMP:20120730T142829
    PRIORITY:1
    SEQUENCE:0
    UID:61b1721e-05f4-4fdc-bc37-802c0254d818
    END:VEVENT
    END:VCALENDAR";

     
  • mayeaonaize
    mayeaonaize
    2012-10-26

    We are also having the same issue under load