sparoid 1.0.18 → 1.0.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d3f9a0d1d95953662422a99f8d0170ce0db8df6ec82042e7f7d6d32e1721853
4
- data.tar.gz: b2f702533aa2d6e1a96aed917a8cc77f8aa8916395944174c74644379392d7b8
3
+ metadata.gz: cd5b6193a911ddfbe06a7a01a2ad1abe3b2c4f60c090aaac4b6b2b6c6ac3dd3e
4
+ data.tar.gz: 622b9465e33bc1b69072450cf619ac2dcf7bf6ac3b1a70276a5f56c4c0d36907
5
5
  SHA512:
6
- metadata.gz: c1803bdedaca58f7e172516864f502693e2478e43b7d9d5b8a0b5f306bb6284d4d19066e23235e9825c5f87ba0567f71388f19df52148cbce2637a17b8afd6d3
7
- data.tar.gz: beb7813a740aa8d52d2689ee26c65872a45f991a9c2d2b937a46ba9451926471a064ca6635056441609a7bc8dfade4ef97aed2de130615b23d269e4ef308469e
6
+ metadata.gz: 8e773ffe52658eecff5b673f0b886a7bd40118654d24602b5c7bd50dbd1dd9a37561b28d51e9dcc2d93557212081f282a6b855f026a22ef646e013ea4c827755
7
+ data.tar.gz: bff75047af985b79ee7a1fc53c40abb3f6d15f5cad4cff86f94430cb599c246ce0a240e20e6c8fd1c4c53a8f79c447b142c69669093409979d10265ce6aa34f9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.0.20] - 2022-10-11
2
+
3
+ - Ignore EISCONN errors (already connected) error as BSD raises on second connect_nonblock
4
+ - Don't read from public ip disk cache in Sparoid::Instance
5
+
6
+ ## [1.0.19] - 2022-10-11
7
+
8
+ - Fix nil error on timeout
9
+
1
10
  ## [1.0.18] - 2022-10-10
2
11
 
3
12
  - Only resolv the IP(s) once
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sparoid
4
- VERSION = "1.0.18"
4
+ VERSION = "1.0.20"
5
5
  end
data/lib/sparoid.rb CHANGED
@@ -6,7 +6,7 @@ require "openssl"
6
6
  require "resolv"
7
7
 
8
8
  # Single Packet Authorisation client
9
- module Sparoid
9
+ module Sparoid # rubocop:disable Metrics/ModuleLength
10
10
  extend self
11
11
 
12
12
  SPAROID_CACHE_PATH = ENV.fetch("SPAROID_CACHE_PATH", "/tmp/.sparoid_public_ip")
@@ -38,7 +38,7 @@ module Sparoid
38
38
  end
39
39
 
40
40
  # Connect to a TCP server and pass the FD to the parent
41
- def fdpass(ips, port, connect_timeout: 10)
41
+ def fdpass(ips, port, connect_timeout: 10) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
42
42
  # try connect to all IPs
43
43
  sockets = ips.map do |ip|
44
44
  Socket.new(Socket::AF_INET, Socket::SOCK_STREAM).tap do |s|
@@ -47,17 +47,22 @@ module Sparoid
47
47
  end
48
48
  # wait for any socket to be connected
49
49
  until sockets.empty?
50
- _, writeable, = IO.select(nil, sockets, nil, connect_timeout)
50
+ _, writeable, errors = IO.select(nil, sockets, nil, connect_timeout) || break
51
+ errors.each { |s| sockets.delete(s) }
51
52
  writeable.each do |s|
52
53
  idx = sockets.index(s)
53
54
  sockets.delete_at(idx) # don't retry this socket again
54
55
  ip = ips.delete_at(idx) # find the IP for the socket
55
- s.connect_nonblock(Socket.sockaddr_in(port, ip)) # check for errors
56
+ begin
57
+ s.connect_nonblock(Socket.sockaddr_in(port, ip)) # check for errors
58
+ rescue Errno::EISCONN
59
+ # already connected, continue
60
+ rescue SystemCallError
61
+ next # skip connection errors, hopefully at least one succeeds
62
+ end
56
63
  # pass the connected FD to the parent process over STDOUT
57
64
  Socket.for_fd(1).sendmsg "\0", 0, nil, Socket::AncillaryData.unix_rights(s)
58
65
  exit 0 # exit as fast as possible so that other sockets don't connect
59
- rescue SystemCallError
60
- next # ignore connection errors, hopefully at least one succeeds
61
66
  end
62
67
  end
63
68
  exit 1 # all connections failed
@@ -129,7 +134,7 @@ module Sparoid
129
134
  Resolv::IPv4.create f.read
130
135
  end
131
136
  rescue ArgumentError => e
132
- return write_cache if e.message =~ /cannot interpret as IPv4 address/
137
+ return write_cache if /cannot interpret as IPv4 address/.match?(e.message)
133
138
 
134
139
  raise e
135
140
  end
@@ -163,5 +168,9 @@ module Sparoid
163
168
  def public_ip
164
169
  @public_ip ||= super
165
170
  end
171
+
172
+ def cached_public_ip
173
+ @public_ip
174
+ end
166
175
  end
167
176
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.18
4
+ version: 1.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Hörberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-10 00:00:00.000000000 Z
11
+ date: 2022-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor