Handle nodeinfo timeouts gracefully

some (especially bigger pods) are sometimes slow to respond with
statistics, so lets handle that gracefully and not mark the pods as
down.
This commit is contained in:
Benjamin Neff 2022-07-23 18:04:22 +02:00
parent b29675fead
commit 78b28c3d54
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
2 changed files with 11 additions and 3 deletions

View file

@ -129,14 +129,14 @@ class ConnectionTester
version, url = ni_urls.max version, url = ni_urls.max
find_software_version(version, http.get(url).body) find_software_version(version, http.get(url).body)
end end
rescue Faraday::ClientError => e
raise HTTPFailure, "#{e.class}: #{e.message}"
rescue NodeInfoFailure => e rescue NodeInfoFailure => e
raise e raise e
rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError => e rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError, Faraday::TimeoutError => e
raise NodeInfoFailure, "#{e.class}: #{e.message}" raise NodeInfoFailure, "#{e.class}: #{e.message}"
rescue JSON::JSONError => e rescue JSON::JSONError => e
raise NodeInfoFailure, e.message[0..255].encode(Encoding.default_external, undef: :replace) raise NodeInfoFailure, e.message[0..255].encode(Encoding.default_external, undef: :replace)
rescue Faraday::ClientError => e
raise HTTPFailure, "#{e.class}: #{e.message}"
rescue StandardError => e rescue StandardError => e
unexpected_error(e) unexpected_error(e)
end end

View file

@ -172,6 +172,14 @@ describe ConnectionTester do
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure) expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
end end
it "handles timeout gracefully" do
ni_wellknown = {links: [{rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}]}
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
.to_return(status: 200, body: JSON.generate(ni_wellknown))
stub_request(:get, "#{url}/nodeinfo/1.0").to_raise(Faraday::TimeoutError.new)
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
end
it "handles a invalid jrd document gracefully" do it "handles a invalid jrd document gracefully" do
invalid_wellknown = {links: {rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}} invalid_wellknown = {links: {rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}}
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}") stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")