logstash-input-unix 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 211693d1622019fadfcdd5f41b94b7e15594abc983aa54000ea59353392b5d4e
4
- data.tar.gz: a8b25c6eb9e1627b502b9177f17510d0e631a72c87883058f3d1f2fa93cb145e
3
+ metadata.gz: dce11755b6f6a09ad708f79ee8d9e85fb87e0d98bf2aaedb6d47a316e1de6731
4
+ data.tar.gz: 84c73daebb51aa1813b528e42113e1a26f73a5162ced25a8c9043648daf54f14
5
5
  SHA512:
6
- metadata.gz: 8c3c0d4cc5bcdee9fb3a32de4593764f9b458861401569ecd16b6055bb905b4d0bf06da68824d0a8358a77e7f4bce2546736a28c407a6a02535150e85364d375
7
- data.tar.gz: da09882dac50d95baef03af89fc1b577ddbd31576d28cbdd02dc42fa350284512050480b231dd59ac6da247d8ec84a71c728ab656a29eb1cf443c0b63a440353
6
+ metadata.gz: a259754acac7b218a5f62f6341f981266833a26395f3fd4341fcec6ed1af843d891561937cd7a16a2478863d2bd7a5d61b85dfe62a00b4ee3f340b35f3ce02d6
7
+ data.tar.gz: f85ae87765a0c9ddde40a91d8b4438d4e62d6ec68b1abb187d6c59fa3e643f4ce624656f97a13fd84fde86e85c63021e46f8eafddef1ba05ea8a9557a312b2ca
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.1.2
2
+ - Fix: eliminate high CPU usage when data timeout is disabled and no data is available on the socket [#30](https://github.com/logstash-plugins/logstash-input-unix/pull/30)
3
+
1
4
  ## 3.1.1
2
5
  - Fix: unable to stop plugin (on LS 6.x) [#29](https://github.com/logstash-plugins/logstash-input-unix/pull/29)
3
6
  - Refactor: plugin internals got reviewed for `data_timeout => ...` to work reliably
@@ -84,16 +84,15 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
84
84
  begin
85
85
  hostname = Socket.gethostname
86
86
  while !stop?
87
- data = socket.read_nonblock(16384, exception: false)
88
-
89
- if data == :wait_readable
90
- if @data_timeout == -1 || IO.select([socket], nil, nil, @data_timeout)
91
- next # retry socket read
92
- else
93
- # socket not ready after @data_timeout seconds
94
- @logger.info("Closing connection after read timeout", :path => @path)
95
- return
96
- end
87
+ data = io_interruptable_readpartial(socket, 16384, @data_timeout)
88
+
89
+ if data == :data_timeout
90
+ # socket not ready after @data_timeout seconds
91
+ @logger.info("Closing connection after read timeout", :path => @path)
92
+ return
93
+ elsif data == :stopping
94
+ @logger.trace("Shutdown in progress", :path => @path)
95
+ next # let next loop handle graceful stop
97
96
  end
98
97
 
99
98
  @codec.decode(data) do |event|
@@ -118,6 +117,35 @@ class LogStash::Inputs::Unix < LogStash::Inputs::Base
118
117
  end
119
118
  end
120
119
 
120
+ ##
121
+ # Emulates `IO#readpartial` with a timeout and our plugin's stop-condition,
122
+ # limiting blocking calls to windows of 10s or less to ensure it can be interrupted.
123
+ #
124
+ # @param readable_io [IO] the IO to read from
125
+ # @param maxlen [Integer] the max bytes to be read
126
+ # @param timeout [Number] the maximum number of seconds to , or -1 to disable timeouts
127
+ #
128
+ # @return [:data_timeout] if timeout was reached before bytes were available
129
+ # @return [:stopping] if plugin stop-condition was detected before bytes were available
130
+ # @return [String] a non-empty string if bytes became available before the timeout was reached
131
+ def io_interruptable_readpartial(readable_io, maxlen, timeout)
132
+
133
+ data_timeout_deadline = timeout < 0 ? nil : Time.now + timeout
134
+ maximum_blocking_seconds = timeout < 0 || timeout > 10 ? 10 : timeout
135
+
136
+ loop do
137
+ return :stopping if stop?
138
+ result = readable_io.read_nonblock(maxlen, exception: false)
139
+
140
+ return result if result.kind_of?(String)
141
+ raise EOFError if result.nil?
142
+
143
+ return :data_timeout if (data_timeout_deadline && data_timeout_deadline < Time.now)
144
+ IO.select([readable_io], nil, nil, maximum_blocking_seconds)
145
+ end
146
+ end
147
+ private :io_interruptable_readpartial
148
+
121
149
  private
122
150
  def server?
123
151
  @mode == "server"
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-unix'
4
- s.version = '3.1.1'
4
+ s.version = '3.1.2'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Reads events over a UNIX socket"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-unix
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-23 00:00:00.000000000 Z
11
+ date: 2022-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement