Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Unhandled Exception: System.IndexOutOfRangeException #33

Closed
evan opened this issue Mar 31, 2014 · 3 comments
Closed

Unhandled Exception: System.IndexOutOfRangeException #33

evan opened this issue Mar 31, 2014 · 3 comments

Comments

@evan
Copy link

evan commented Mar 31, 2014

The following fatal exception occurs in our app:

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at System.Collections.Generic.List`1.Add(T item)
  at StatsdClient.Statsd.Add[TCommandType](String name, Double value)
...

I believe this may be a thread safety issue. Is access to the Commands List thread safe?

@evan
Copy link
Author

evan commented Mar 31, 2014

It is not. I believe you want to use a ConcurrentQueue here.

@DarrellMozingo
Copy link
Collaborator

Hi Evan,

I took a look at this and was able to reproduce when hitting the Add method with upwards of a million concurrent calls. ConcurrentQueue won't work here because a) we're still targeting .NET 3.5 and ConcurrentQueue is in 4.5, and b) the List type is on the IStatsd interface (unfortunately), so I don't want to break that contract for anyone.

I'll give a go at doing some basic thread locking to see if it'll solve the issue. If not, we may look at breaking the two points above and using one of the newer built in thread safe types.

Thanks for reporting this!

@DarrellMozingo
Copy link
Collaborator

Just pushed this in 1.0.0.17. Let me know if you have any problems.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants