Skip to content

Commit 9a7eb06

Browse files
committed
ensure tcp socket is freed after teardown
1 parent fcb9bf1 commit 9a7eb06

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/logstash/inputs/http.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ def lowercase_keys(hash)
9797

9898
public
9999
def teardown
100-
@server.stop(true)
100+
if @server
101+
@server.stop(true)
102+
begin
103+
@server.binder.close if @server.binder
104+
rescue IOError
105+
end
106+
end
101107
end
102108

103109
end # class LogStash::Inputs::Http

spec/inputs/http_spec.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
describe LogStash::Inputs::Http do
77

88
let(:agent) { FTW::Agent.new }
9+
let(:queue) { Queue.new }
910

10-
it "should read events with json codec" do
11-
conf = <<-CONFIG
12-
input {
13-
http { codec => json }
14-
}
15-
CONFIG
11+
after :each do
12+
subject.teardown
13+
end
1614

17-
event = input(conf) do |pipeline, queue|
18-
agent.post!("http://127.0.0.1:8080/meh.json", :body => { "message" => "Hello" }.to_json)
19-
queue.pop
15+
context "with json codec" do
16+
subject { LogStash::Inputs::Http.new("codec" => "json") }
17+
it "should parse the json body" do
18+
subject.register
19+
Thread.new { subject.run(queue) }
20+
agent.post!("http://localhost:8080/meh.json", :body => { "message" => "Hello" }.to_json)
21+
event = queue.pop
22+
expect(event["message"]).to eq("Hello")
2023
end
24+
end
2125

2226
context "with :ssl => false" do
2327
subject { LogStash::Inputs::Http.new("ssl" => false) }

0 commit comments

Comments
 (0)