Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent ENOBUFS errors by skipping UDP send buffer size configuration #392

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ section below.

## Unreleased changes

## Version 3.9.9

- [#392](https://github.com/Shopify/statsd-instrument/pull/392) - Prevent ENOBUFS errors when using UDP, by skipping setting socket buffer size.

## Version 3.9.8

- [#390](https://github.com/Shopify/statsd-instrument/pull/391) - Fixing bug in Environment when using UDS. The max packet size option was not being passed to the
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ platform :mri do
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.2")
gem "vernier", require: false
end

# From Ruby >= 3.5, logger is not part of the stdlib anymore
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.5")
gem "logger"
end
Comment on lines +23 to +26

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything about this in the 3.4 release notes, was this communicated somewhere?

end
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipv6 support? cool!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to breaking our stats logging to Datadog. We're on a k8s stack so I'm guessing it's something to do with the IPv6 support? We're investigating now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We suspect it was due to us using a socat proxy bound to IPv4 only. We proxy through a central Datadog agent that forwards our stats to Datadog.

It will take a bit to update and test across our environments to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to put up a PR in case it turns out to be an issue.

setup_socket(udp_socket)&.tap do |s|
s.connect(@host, @port)
s.connect(host, port)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/statsd/instrument/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module StatsD
module Instrument
VERSION = "3.9.8"
VERSION = "3.9.9"
end
end
14 changes: 0 additions & 14 deletions test/udp_sink_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,11 @@ def test_socket_error_should_invalidate_socket
seq = sequence("connect_fail_connect_succeed")

# First attempt
socket.expects(:setsockopt)
.with(Socket::SOL_SOCKET, Socket::SO_SNDBUF, StatsD::Instrument::UdpConnection::DEFAULT_MAX_PACKET_SIZE)
.in_sequence(seq)
socket.expects(:getsockopt)
.with(Socket::SOL_SOCKET, Socket::SO_SNDBUF)
.returns(mock(int: StatsD::Instrument::UdpConnection::DEFAULT_MAX_PACKET_SIZE))
.in_sequence(seq)
socket.expects(:connect).with("localhost", 8125).in_sequence(seq)
socket.expects(:send).raises(Errno::EDESTADDRREQ).in_sequence(seq)
socket.expects(:close).in_sequence(seq)

# Second attempt after error
socket.expects(:setsockopt)
.with(Socket::SOL_SOCKET, Socket::SO_SNDBUF, StatsD::Instrument::UdpConnection::DEFAULT_MAX_PACKET_SIZE)
.in_sequence(seq)
socket.expects(:getsockopt)
.with(Socket::SOL_SOCKET, Socket::SO_SNDBUF)
.returns(mock(int: StatsD::Instrument::UdpConnection::DEFAULT_MAX_PACKET_SIZE))
.in_sequence(seq)
socket.expects(:connect).with("localhost", 8125).in_sequence(seq)
socket.expects(:send).twice.returns(1).in_sequence(seq)
socket.expects(:close).in_sequence(seq)
Expand Down
Loading