lukevenediger / statsd-csharp-client

A simple c# client library for statsd and statsd.net
MIT License
47 stars 20 forks source link

SocketException: An invalid argument was supplied #8

Closed niemyjski closed 8 years ago

niemyjski commented 9 years ago

I've been getting the following issue and trying to track it down. I'm not sure 100% what's causing it but I think that maybethe client doesn't handle when the statsd server goes down?

System.Net.Sockets.SocketException: An invalid argument was supplied
at System.Net.Sockets.Socket.Send(System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) at offset 23
at System.Net.Sockets.UdpClient.Send(System.Byte[] dgram, System.Int32 bytes) at offset 39
at StatsdClient.UdpOutputChannel.Send(System.String line) at offset 12
at StatsdClient.Statsd.SendMetric(System.String metricType, System.String name, System.String prefix, System.String value, System.String postFix) at offset 19
at StatsdClient.Statsd.SendMetric(System.String metricType, System.String name, System.String prefix, System.Int32 value, System.String postFix) at offset 47
at StatsdClient.Statsd.LogGauge(System.String name, System.Int32 value) at offset 0
niemyjski commented 9 years ago

I was able to track this down. It has to do with the udpclient. Basically it's really unreliable and the underlying socket will fail (timeouts, errors etc). I was able to take code that used the udp client and increase the performance from ~20k requests/s to over 90k requests/s (https://github.com/exceptionless/Foundatio/blob/master/src/Foundatio/Metrics/StatsDMetricsClient.cs). I'll try bringing these changes into the library and add some tests.

niemyjski commented 8 years ago

I'm closing this for now, it wasn't resolved but I've yet to figure out how this randomly happens other than to catch and retry.