diff --git a/.travis.yml b/.travis.yml index 594c7d7..107aac6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ rvm: - 2.3.0 - 2.4.0 - jruby-19mode +before_install: gem install bundler -v "< 2" deploy: provider: rubygems api_key: diff --git a/Gemfile.lock b/Gemfile.lock index 6b18067..79e21a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,4 +71,4 @@ DEPENDENCIES test-unit (~> 3.2.0) BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/lib/gelf/transport/tcp.rb b/lib/gelf/transport/tcp.rb index 30240e4..475a1f5 100644 --- a/lib/gelf/transport/tcp.rb +++ b/lib/gelf/transport/tcp.rb @@ -1,6 +1,8 @@ module GELF module Transport class TCP + IO_TIMEOUT = 10 # IO timeout in seconds + attr_reader :addresses # `addresses` Array of [host, port] pairs @@ -60,14 +62,16 @@ def write_socket(socket, message) end def unsafe_write_socket(socket, message) - r,w = IO.select([socket], [socket]) + r, w = IO.select([socket], [socket], [], IO_TIMEOUT) + return false unless r + # Read everything first while r.any? do # don't expect any reads, but a readable socket might # mean the remote end closed, so read it and throw it away. # we'll get an EOFError if it happens. socket.sysread(16384) - r = IO.select([socket]) + r = IO.select([socket], [], [], IO_TIMEOUT) or break end # Now send the payload