chronograf icon indicating copy to clipboard operation
chronograf copied to clipboard

Increase the number of open sockets on Chronograf server

Open alyan2008 opened this issue 9 years ago • 5 comments

Hi

I installed Chronograf on the same server with kapacitor and influxDB. Right after that I noticed the huge increase of open sockets.

image

Is it expected?

alyan2008 avatar Feb 27 '17 20:02 alyan2008

Hi @alyan2008, I'll check it out. What version of chronograf are you using?

goller avatar Feb 27 '17 22:02 goller

@alyan2008 I've been able to reproduce this.

To reproduce run

watch -n1 "sudo lsof -i|grep chronograf"

..play around in the kapacitor rules page by saving a rule over and over again; watch the number of sockets established go up.

goller avatar Feb 28 '17 14:02 goller

Got a theory on this one. We're creating a new http.Transport for each query when InsecureSkipVerify is desired for HTTPS. This happens here: https://github.com/influxdata/chronograf/blob/master/influx/influx.go#L77-L80 . The docs for http.Transport state:

By default, Transport caches connections for future re-use. This may leave many open connections when accessing many hosts. [...] Transports should be reused instead of created as needed. Transports are safe for concurrent use by multiple goroutines.

I couldn't find a runtime.SetFinalizer for http.Transport in the stdlib that would automagically clean up open sockets on GC, so my guess is when that happens the sockets are orphaned but still allocated to the process and left open?

timraymond avatar Feb 28 '17 15:02 timraymond

@timraymond just tried that out for influx queries... yup, we need to keep around the transport.

I haven't figured out kapacitor proxying yet. I wonder if I need to reuse the Transport here: https://github.com/influxdata/chronograf/blob/master/server/proxy.go#L58

goller avatar Feb 28 '17 15:02 goller

Hi @alyan2008, we fixed the socket leaks for queries to Influx in PR #942. Thanks for reporting it!

We were commenting that it was pretty cool that you found a problem with chronograf using chronograf 👍

goller avatar Feb 28 '17 22:02 goller