Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make usage of the new stop semantics to properly shutdown the plugin #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 2 additions & 10 deletions lib/logstash/inputs/zeromq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def register
require "logstash/util/zeromq"
self.class.send(:include, LogStash::Util::ZeroMQ)

@run_mutex = Mutex.new
@run = true
case @topology
when "pair"
zmq_const = ZMQ::PAIR
Expand Down Expand Up @@ -116,7 +114,6 @@ def register
end # def register

def close
@run_mutex.synchronize{@run = false}
error_check(@zsocket.close, "while closing the zmq socket")
context.terminate
end # def close
Expand All @@ -134,6 +131,8 @@ def run(output_queue)
m1 = ""
rc = @zsocket.recv_string(m1, ZMQ::DONTWAIT)
next if rc == -1 && ZMQ::Util.errno == ZMQ::EAGAIN
error_check(rc, "in recv_string")

@logger.debug("ZMQ receiving", :event => m1)
msg = m1
# If we have more parts, we'll eat the first as the topic
Expand All @@ -152,9 +151,6 @@ def run(output_queue)
output_queue << event
end
end
rescue LogStash::ShutdownSignal
# shutdown
return
rescue => e
@logger.debug("ZMQ Error", :subscriber => @zsocket,
:exception => e)
Expand All @@ -167,8 +163,4 @@ def build_source_string
id = @address.first.clone
end

def stop?
!@run
end

end # class LogStash::Inputs::ZeroMQ
3 changes: 1 addition & 2 deletions lib/logstash/util/zeromq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
require "logstash/namespace"

module LogStash::Util::ZeroMQ
CONTEXT = ZMQ::Context.new
# LOGSTASH-400
# see https://github.com/chuckremes/ffi-rzmq/blob/master/lib/ffi-rzmq/socket.rb#L93-117
STRING_OPTS = %w{IDENTITY SUBSCRIBE UNSUBSCRIBE}

def context
CONTEXT
@context ||= ZMQ::Context.new
end

def setup(socket, address)
Expand Down
10 changes: 9 additions & 1 deletion spec/inputs/zeromq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
expect { plugin.close }.to_not raise_error
end

end
context "when interrupting the plugin" do
it_behaves_like "an interruptible input plugin" do
let(:config) { { "topology" => "pushpull" } }
after do
subject.close
end
end
end

end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def input(config, size, &block)
result = size.times.inject([]) do |acc|
acc << queue.pop
end
plugin.close
plugin.do_stop
pipeline_thread.join
result
end # def input
Expand Down