From 71ab700a530869564ef4fe82e866fa428a052fd6 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Tue, 20 Aug 2019 12:44:03 +0900 Subject: [PATCH] Block timeout during IO#write to avoid writing invalid bytes Signed-off-by: Yuta Iwama --- lib/fluent/logger/fluent_logger.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fluent/logger/fluent_logger.rb b/lib/fluent/logger/fluent_logger.rb index 13cc667..f4e3e25 100644 --- a/lib/fluent/logger/fluent_logger.rb +++ b/lib/fluent/logger/fluent_logger.rb @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +require 'timeout' require 'msgpack' require 'socket' require 'monitor' @@ -260,7 +261,11 @@ def send_data(data) if @use_nonblock send_data_nonblock(data) else - @con.write data + _, ws = IO.select([], [@con]) + Thread.handle_interrupt(::Timeout::Error => :never) do + # block timeout error during IO#write + ws.first.write(data) + end end #while true # puts "sending #{data.length} bytes"