discourse / prometheus_exporter

A framework for collecting and aggregating prometheus metrics
MIT License
532 stars 154 forks source link

Don't attempt to close a socket that is already closed. #142

Closed seandilda closed 3 years ago

seandilda commented 3 years ago

This change is a result of issues running prometheus_exporter with delayed_job.

delayed_job uses the daemons gem which closes all existing IO objects (https://github.com/thuehlinger/daemons/blob/76a934ab333788964a5d7587648cfc98ffd2b150/lib/daemons/daemonize.rb#L121). After this happens, the PrometheusExporter::Client stops being able to send metrics and instead prints the following error:

Prometheus Exporter, failed to send message closed stream

This change allows PrometheusExporter::Client to detect the closed socket after 25 seconds (MAX_SOCKET_AGE) and clean it up.

SamSaffron commented 3 years ago

This looks like a very safe change ... sure... merging it in!