diff --git a/lib/logstash/event.rb b/lib/logstash/event.rb index 8191fcf31..18b343ca2 100644 --- a/lib/logstash/event.rb +++ b/lib/logstash/event.rb @@ -296,7 +296,6 @@ class LogStash::Event def self.validate_value(value) case value when String - value.force_encoding("UTF-8") if LogStash::Environment.windows? raise("expected UTF-8 encoding for value=#{value}, encoding=#{value.encoding.inspect}") unless value.encoding == Encoding::UTF_8 raise("invalid UTF-8 encoding for value=#{value}, encoding=#{value.encoding.inspect}") unless value.valid_encoding? value diff --git a/lib/logstash/monkeypatches-for-bugs.rb b/lib/logstash/monkeypatches-for-bugs.rb new file mode 100644 index 000000000..f31e1cceb --- /dev/null +++ b/lib/logstash/monkeypatches-for-bugs.rb @@ -0,0 +1,34 @@ +require "logstash/environment" + +if LogStash::Environment.windows? && LogStash::Environment.jruby? then + require "socket" + module JRubyBug2558SocketPeerAddrBugFix + def peeraddr + orig_peeraddr.map do |v| + case v + when String + v.force_encoding(Encoding::UTF_8) + else + v + end + end + end + end + + class << Socket + # Bugfix for jruby #2558 + alias_method :orig_gethostname, :gethostname + def gethostname + return orig_gethostname.force_encoding(Encoding::UTF_8) + end + end + + class TCPSocket + alias_method :orig_peeraddr, :peeraddr + include JRubyBug2558SocketPeerAddrBugFix + end + class UDPSocket + alias_method :orig_peeraddr, :peeraddr + include JRubyBug2558SocketPeerAddrBugFix + end +end diff --git a/lib/logstash/runner.rb b/lib/logstash/runner.rb index 0d8b0cc12..778c3c573 100644 --- a/lib/logstash/runner.rb +++ b/lib/logstash/runner.rb @@ -45,6 +45,7 @@ if ENV["PROFILE_BAD_LOG_CALLS"] || $DEBUGLIST.include?("log") end end # PROFILE_BAD_LOG_CALLS +require "logstash/monkeypatches-for-bugs" require "logstash/monkeypatches-for-debugging" require "logstash/namespace" require "logstash/program"