From 0cb9e0dca087f87ca0fc1d246c5ca2ba8de6e03e Mon Sep 17 00:00:00 2001 From: Marcos Sandim Date: Fri, 12 Sep 2025 17:16:28 -0300 Subject: [PATCH] Fix unable to open StatsD socket. reason: :emfile If StatsD is not available and the packet transmission fails, `Peep.StatsD.send_packets/3` removes the socket from the state but does not close it. This leads to a situation where we try to open a new socket every few seconds and don't close any of them, and end up hitting the maximum file descriptors limit. This change simply closes the socket, freeing up the file descriptor. Error: ``` [error] 2025-09-12 17:15:57.855 unable to open StatsD socket. reason: :emfile {line=150 pid=<0.440.0> file=lib/peep/statsd.ex domain=elixir application=peep mfa=Peep.Statsd.try_to_open_socket/1 } ``` --- lib/peep/statsd.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/peep/statsd.ex b/lib/peep/statsd.ex index 0108ca9..3ab2bc1 100644 --- a/lib/peep/statsd.ex +++ b/lib/peep/statsd.ex @@ -86,6 +86,7 @@ defmodule Peep.Statsd do %__MODULE__{state | statsd_opts: new_opts} {:error, _reason} -> + :gen_udp.close(socket) %__MODULE__{state | socket: nil} end