diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-23 19:04:22 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-24 18:19:04 +0300 |
commit | 78b28c3d54b449ab1439d7dfa8fb2f6a20dfbe13 (patch) | |
tree | dfc5efe248fb106337d9eac24c334ef0a521c9ec | |
parent | b29675fead857cf6370d5ad70cac97f0d975ec3a (diff) |
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.
-rw-r--r-- | lib/connection_tester.rb | 6 | ||||
-rw-r--r-- | spec/lib/connection_tester_spec.rb | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/connection_tester.rb b/lib/connection_tester.rb index 5957b80d5..810a3f2bd 100644 --- a/lib/connection_tester.rb +++ b/lib/connection_tester.rb @@ -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 diff --git a/spec/lib/connection_tester_spec.rb b/spec/lib/connection_tester_spec.rb index 671fec860..a0dce4d4f 100644 --- a/spec/lib/connection_tester_spec.rb +++ b/spec/lib/connection_tester_spec.rb @@ -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}") |