Skip to content

Commit 175b169

Browse files
drbrainhennevogel
authored andcommitted
Only finish started HTTP connections
1 parent 9bf8da7 commit 175b169

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/influxdb/client/http.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def connect_with_retry
5151

5252
yield http
5353
rescue *InfluxDB::NON_RECOVERABLE_EXCEPTIONS => e
54-
http.finish
54+
http.finish if http.started?
5555

5656
raise InfluxDB::ConnectionError, InfluxDB::NON_RECOVERABLE_MESSAGE
5757
rescue Timeout::Error, *InfluxDB::RECOVERABLE_EXCEPTIONS => e
58-
http.finish
58+
http.finish if http.started?
5959

6060
retry_count += 1
6161
unless (config.retry == -1 || retry_count <= config.retry) && !stopped?

spec/influxdb/client_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@
3939
end
4040
end
4141

42+
describe "#connect_with_retry" do
43+
it "raises InfluxDB::ConnectionError when the hostname is unknown" do
44+
subject.config.retry = 0
45+
46+
allow_any_instance_of(Net::HTTP).to receive(:start) do
47+
raise SocketError, "simulate getaddrinfo error"
48+
end
49+
50+
error = InfluxDB::ConnectionError.new "Tried 0 times to reconnect but failed."
51+
expect { subject.send(:connect_with_retry) }.to raise_error(InfluxDB::ConnectionError)
52+
end
53+
end
54+
4255
describe "#full_url" do
4356
it "returns String" do
4457
expect(subject.send(:full_url, "/unknown")).to be_a String

0 commit comments

Comments
 (0)