Skip to content

Commit

Permalink
Prevent ENOBUFS errors by skipping UDP send buffer size configuration
Browse files Browse the repository at this point in the history
The previous implementation attempted to set the UDP socket's send buffer
size, which could lead to ENOBUFS errors in some environments. This change:
- Overrides setup_socket in UDPConnection to skip buffer size configuration
- Improves socket creation by using the correct address family
- Updates error message to be more accurate ("Failed to setup socket")

This prevents potential buffer-related errors while maintaining the original
functionality for other connection types.
  • Loading branch information
pedro-stanaka committed Jan 13, 2025
1 parent 4045921 commit 7085d70
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/statsd/instrument/connection_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setup_socket(original_socket)
original_socket
rescue IOError => e
StatsD.logger.debug do
"[#{self.class.name}] Failed to create socket: #{e.class}: #{e.message}"
"[#{self.class.name}] Failed to setup socket: #{e.class}: #{e.message}"
end
nil
end
Expand Down
9 changes: 7 additions & 2 deletions lib/statsd/instrument/udp_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ def type

private

def setup_socket(original_socket)
original_socket
end

def socket
@socket ||= begin
udp_socket = UDPSocket.new
family = Addrinfo.udp(host, port).afamily
udp_socket = UDPSocket.new(family)
setup_socket(udp_socket)&.tap do |s|
s.connect(@host, @port)
s.connect(host, port)
end
end
end
Expand Down

0 comments on commit 7085d70

Please sign in to comment.