openfact 6.1.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4daa243a80d8ba47b89553843beda2cb577af1592688fc50824b28b4453c4e72
4
- data.tar.gz: 1e1cbf1a2817cf2eb906ed791fd58bc60d0b1acaa229ace93e8a55d2f353c758
3
+ metadata.gz: 3bad8912857bdd63fa3c31cacf9e6e5d6113e85216f1a57662c0b0101c20f2f9
4
+ data.tar.gz: 16f3de88eecfd77e0f67d7d85c48d07b228fbad61d020a7998841d184ee327a5
5
5
  SHA512:
6
- metadata.gz: 1791dc19b98a3676c9adcbc03df513ba5907d123159de09e6a67317ecdee1003eb5c1ea057b9099d81972c10f39e55a9f73f02f5a498918cc7fd227a710990b6
7
- data.tar.gz: ba01bd6bf64dfe485897a0be96bcb8f7686b8500298f3205b28c7d8f20905b3d4db9530e11221be1e5bc55e92370eea7d82f0dcc80d82eaf58d19b4f6b74a861
6
+ metadata.gz: 0d7c6eda30361358651330ccd7a1a2dc6ffab30530e6a67806f5e65249128870bd2faf75553176c829e26fb9850e805b6f581733efe5714b06873ae5c5c60e56
7
+ data.tar.gz: 1fc5de3dc1cfafc7039fae02c708fc6baa8d36d2cb56bdabdf85fe2be43d0eac82bc24b7643e8f9921e28addea138778453ea2176bc38314ddafdc26c8e93382
@@ -9,6 +9,11 @@ module Facter
9
9
 
10
10
  init_resolver
11
11
 
12
+ # Upper bound, in seconds, for the fqdn lookup. A hung name service
13
+ # otherwise stalls fact collection until the agent's runtimeout fires
14
+ # (OpenVoxProject/openvox#485). Only applied on Rubies that honour it.
15
+ FQDN_LOOKUP_TIMEOUT = 10
16
+
12
17
  class << self
13
18
  private
14
19
 
@@ -48,14 +53,27 @@ module Facter
48
53
 
49
54
  def retrieve_with_addrinfo(host)
50
55
  begin
51
- name = Socket.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME)[0]
56
+ addr = Addrinfo.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME,
57
+ **addrinfo_options)[0]
52
58
  rescue StandardError => e
53
- @log.debug("Socket.getaddrinfo failed to retrieve fqdn for hostname #{host} with: #{e}")
59
+ @log.debug("Addrinfo.getaddrinfo failed to retrieve fqdn for hostname #{host} with: #{e}")
54
60
  return
55
61
  end
56
- return if name.nil? || name.empty? || host == name[2] || name[2] == name[3]
57
62
 
58
- name[2]
63
+ name = addr&.canonname
64
+ return if name.nil? || name.empty? || host == name || name == addr.ip_address
65
+
66
+ name
67
+ end
68
+
69
+ # Addrinfo.getaddrinfo only honours the timeout keyword from Ruby 4.0
70
+ # on. Older MRI accepts and ignores it; JRuby does not accept it.
71
+ def addrinfo_options
72
+ addrinfo_timeout_supported? ? { timeout: FQDN_LOOKUP_TIMEOUT } : {}
73
+ end
74
+
75
+ def addrinfo_timeout_supported?
76
+ RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('4.0')
59
77
  end
60
78
 
61
79
  def exists_and_valid_fqdn?(fqdn, hostname)
@@ -10,6 +10,11 @@ module Facter
10
10
 
11
11
  init_resolver
12
12
 
13
+ # Upper bound, in seconds, for the fqdn lookup. A hung name service
14
+ # otherwise stalls fact collection until the agent's runtimeout fires
15
+ # (OpenVoxProject/openvox#485). Only applied on Rubies that honour it.
16
+ FQDN_LOOKUP_TIMEOUT = 10
17
+
13
18
  class << self
14
19
  private
15
20
 
@@ -65,16 +70,35 @@ module Facter
65
70
 
66
71
  def retrieve_fqdn_for_host(host)
67
72
  begin
68
- name = Socket.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME)[0]
73
+ addr = Addrinfo.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME,
74
+ **addrinfo_options)[0]
69
75
  rescue StandardError => e
70
- log.debug("Socket.getaddrinfo failed to retrieve fqdn for hostname #{host} with: #{e}")
76
+ log.debug("Addrinfo.getaddrinfo failed to retrieve fqdn for hostname #{host} with: #{e}")
77
+ # The name service is not answering. The FFI lookup below has no
78
+ # timeout and holds the GVL while it waits, so do not try it.
79
+ return if lookup_timed_out?(e)
71
80
  end
72
81
 
73
- return name[2] if !name.nil? && !name.empty? && host != name[2] && name[2] != name[3]
82
+ name = addr&.canonname
83
+ return name if exists_and_not_empty?(name) && host != name && name != addr.ip_address
74
84
 
75
85
  retrieve_fqdn_for_host_with_ffi(host)
76
86
  end
77
87
 
88
+ def lookup_timed_out?(error)
89
+ error.is_a?(Errno::ETIMEDOUT) || (defined?(IO::TimeoutError) && error.is_a?(IO::TimeoutError))
90
+ end
91
+
92
+ # Addrinfo.getaddrinfo only honours the timeout keyword from Ruby 4.0
93
+ # on. Older MRI accepts and ignores it; JRuby does not accept it.
94
+ def addrinfo_options
95
+ addrinfo_timeout_supported? ? { timeout: FQDN_LOOKUP_TIMEOUT } : {}
96
+ end
97
+
98
+ def addrinfo_timeout_supported?
99
+ RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('4.0')
100
+ end
101
+
78
102
  def retrieve_fqdn_for_host_with_ffi(host)
79
103
  require_relative '../../../facter/util/resolvers/ffi/hostname'
80
104
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '6.1.0' unless defined?(VERSION)
4
+ VERSION = '6.2.0' unless defined?(VERSION)
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openfact
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenVox Project
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 1.90.0
90
+ version: 1.91.0
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: 1.90.0
97
+ version: 1.91.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rubocop-performance
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -1287,7 +1287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1287
1287
  - !ruby/object:Gem::Version
1288
1288
  version: '0'
1289
1289
  requirements: []
1290
- rubygems_version: 4.0.16
1290
+ rubygems_version: 4.0.20
1291
1291
  specification_version: 4
1292
1292
  summary: OpenFact, a system inventory tool
1293
1293
  test_files: []