Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 0 deletions lib/datadog/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def write(message)
bad_socket = !@socket_path.nil? && (
boom.is_a?(Errno::ECONNREFUSED) ||
boom.is_a?(Errno::ECONNRESET) ||
boom.is_a?(Errno::ENOTCONN) ||
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It might actually be better to not add this and instead relax the retry conditions on this line

if retries <= 1 && boom.is_a?(IOError) && boom.message =~ /closed stream/i

to just

        if retries <= 1

In our case as well as I'm sure in many others, we'd much rather immediately retry establishing the socket and resending the message rather than losing the message and having to wait for the next one for the socket to re-establish itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I changed the logic to retry the same message upon ENOTCONN

boom.is_a?(Errno::ENOENT)
)
if bad_socket
Expand Down
25 changes: 25 additions & 0 deletions spec/statsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,31 @@ class Datadog::Statsd::SomeClass; end
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
@fake_socket = Minitest::Mock.new
Expand Down