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
find_software_version(version, http.get(url).body)
end
rescue Faraday::ClientError => e
raise HTTPFailure, "#{e.class}: #{e.message}"
rescue NodeInfoFailure => 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}"
rescue JSON::JSONError => e
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
unexpected_error(e)
end

View file

@ -172,6 +172,14 @@ describe ConnectionTester do
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
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
invalid_wellknown = {links: {rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}}
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")