Skip to content
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
1 change: 0 additions & 1 deletion lib/datadog/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def write(message)
bad_socket = !@socket_path.nil? && (
boom.is_a?(Errno::ECONNREFUSED) ||
boom.is_a?(Errno::ECONNRESET) ||
boom.is_a?(Errno::ENOTCONN) ||
boom.is_a?(Errno::ENOENT)
)
if bad_socket
Expand Down
56 changes: 31 additions & 25 deletions spec/statsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,37 @@ class Datadog::Statsd::SomeClass; end
@log.string.must_include 'Statsd: SocketError'
end
end

describe "handling not connected socket" do
before do
@statsd.connection.instance_variable_set(:@logger, Logger.new(@log = StringIO.new))
end

it "tries to reconnect once" do
@statsd.connection.expects(:socket).times(2).returns(socket)
socket.expects(:send).returns("YEP") # 2nd call
socket.expects(:send).raises(Errno::ENOTCONN.new("closed stream")) # first call

@statsd.increment('foobar')
end

it "ignores and logs if it fails to reconnect" do
@statsd.connection.expects(:socket).times(2).returns(socket)
socket.expects(:send).raises(RuntimeError) # 2nd call
socket.expects(:send).raises(Errno::ENOTCONN.new) # first call

assert_nil @statsd.increment('foobar')
@log.string.must_include 'Statsd: RuntimeError'
end

it "ignores and logs errors while trying to reconnect" do
socket.expects(:send).raises(Errno::ENOTCONN.new)
@statsd.connection.expects(:connect).raises(SocketError)

assert_nil @statsd.increment('foobar')
@log.string.must_include 'Statsd: SocketError'
end
end

describe "UDS error handling" do
before do
Expand Down Expand Up @@ -586,31 +617,6 @@ class Datadog::Statsd::SomeClass; end
@fake_socket2.verify
end
end

describe "when socket throws not connected error" do
before do
@fake_socket = Minitest::Mock.new
@fake_socket.expect(:connect, true) { true }
@fake_socket.expect :sendmsg_nonblock, true, ['foo:1|c']
@fake_socket.expect(:sendmsg_nonblock, true) { raise Errno::ENOTCONN }

@fake_socket2 = Minitest::Mock.new
@fake_socket2.expect(:connect, true) { true }
@fake_socket2.expect :sendmsg_nonblock, true, ['bar:1|c']
end

it "should ignore message and try reconnect on next call" do
Socket.stub(:new, @fake_socket) do
@statsd.increment('foo')
end
@statsd.increment('baz')
Socket.stub(:new, @fake_socket2) do
@statsd.increment('bar')
end
@fake_socket.verify
@fake_socket2.verify
end
end

describe "when socket is full" do
before do
Expand Down