omq 0.30.0 → 0.30.2

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: c307ca5bbfb86b9b0b8641808900e6a4ebd20d850b71debd7a9bb93a481793f1
4
- data.tar.gz: 56ba1b9a6598847a0fc409fb7689ade3a6acc551b95c893a5e32f0f0900d2783
3
+ metadata.gz: ffbc4732e7488889e31f45a6940f4b1b52ea4c357f2fb1a8b8610686938cd7f1
4
+ data.tar.gz: 5f079c8ed80726142b3c4820b6c4c863f86384f06636c4b93d7eb9a7f8ad870e
5
5
  SHA512:
6
- metadata.gz: 104203f451e68f6e7847a2c8c5b51651ae307b7442224c955f42241ebcbee38cfe1eb5fccfb04ba695c0f17ad9945e806e6e51436607c231b68592f2057c09a3
7
- data.tar.gz: 5e1667fecd724027ec2deb01e9df31bab619a8f03d00bfda9ef579054871d060516c46192be83c5ab1aa517c7b2edd0839883a73f3eff972bda92af6ac66acc7
6
+ metadata.gz: c30ba7e7b80e63a12a39fd6579179fa80d41deed838fb10f096adfab44ed3038b9f1d8e2092dd07c02f8d911050ed6abf040a89e67526f5c1f489b998cd971e4
7
+ data.tar.gz: a1081d832c4c15f8e03eba6d6d492ca6a6f8ce8211f2ec539d3a1443345ab7b9af8b6e2a58e668d4dbc2948fb3a0e2378b981843fa7fdbcb3bb011cc7c510473
data/CHANGELOG.md CHANGED
@@ -2,6 +2,35 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.30.2] - 2026-12-02
6
+
7
+ ### Fixed
8
+
9
+ - A `tcp://` dial to a free local port can get that same port as its source
10
+ and connect to itself (zeromq/libzmq#4958). The dialer now closes that
11
+ socket and retries as if refused. Before, PAIR, DEALER, ROUTER, CHANNEL
12
+ and PEER sockets completed the handshake with themselves and stayed
13
+ connected to themselves.
14
+
15
+ ## [0.30.1] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - `Engine.endpoint_uri(endpoint)`: the URI `#bind` and `#connect` return,
20
+ built by the transport when it has `.endpoint_uri`. The native backends use
21
+ it for the endpoints they resolve.
22
+
23
+ ### Fixed
24
+
25
+ - `#bind` and `#connect` return a URI that keeps the @ of an abstract IPC
26
+ name. They returned `ipc://name` for `ipc://@name`, because `URI.parse`
27
+ reads the @ as the end of an empty userinfo, and connecting to that dialed
28
+ a relative file path. Abstract names `URI.parse` rejects, such as ones with
29
+ spaces, no longer raise after the bind.
30
+ - `#bind` and `#connect` no longer raise for an IPC file path `URI.parse`
31
+ rejects, such as one with a space. They raised once the socket was already
32
+ bound or dialing.
33
+
5
34
  ## [0.30.0] - 2026-11-26
6
35
 
7
36
  ### Added
data/lib/omq/engine.rb CHANGED
@@ -33,6 +33,21 @@ module OMQ
33
33
  class << self
34
34
  # @return [Hash{String => Module}] registered transports
35
35
  attr_reader :transports
36
+
37
+
38
+ # The URI {#bind} and {#connect} return for +endpoint+. A transport
39
+ # with +.endpoint_uri+ builds it: IPC keeps the @ of abstract names.
40
+ # The native backends use it for the endpoints they resolve.
41
+ #
42
+ # @param endpoint [String]
43
+ # @return [URI::Generic]
44
+ #
45
+ def endpoint_uri(endpoint)
46
+ transport = @transports[endpoint[/\A[^:]+/]]
47
+ return transport.endpoint_uri(endpoint) if transport.respond_to?(:endpoint_uri)
48
+
49
+ URI.parse(endpoint)
50
+ end
36
51
  end
37
52
 
38
53
 
@@ -217,7 +232,7 @@ module OMQ
217
232
  @listeners[listener.endpoint] = listener
218
233
  remember_bind_alias(endpoint, listener.endpoint)
219
234
  emit_monitor_event(:listening, endpoint: listener.endpoint)
220
- URI.parse(listener.endpoint)
235
+ Engine.endpoint_uri(listener.endpoint)
221
236
  rescue => error
222
237
  emit_monitor_event(:bind_failed, endpoint: endpoint, detail: { error: error })
223
238
  raise
@@ -245,7 +260,7 @@ module OMQ
245
260
  schedule_reconnect(endpoint, delay: 0)
246
261
  end
247
262
 
248
- URI.parse(endpoint)
263
+ Engine.endpoint_uri(endpoint)
249
264
  end
250
265
 
251
266
 
@@ -14,6 +14,21 @@ module OMQ
14
14
  Engine.transports["ipc"] = self
15
15
 
16
16
 
17
+ # The URI of an endpoint +URI.parse+ can't keep, with the path as
18
+ # given. +URI.parse+ reads the @ of "ipc://@name" as the end of an
19
+ # empty userinfo, so its #to_s is "ipc://name", a relative file path,
20
+ # and it rejects paths with spaces and similar characters.
21
+ #
22
+ class PathURI < URI::Generic
23
+ # @return [String] e.g. "ipc://@name"
24
+ #
25
+ def to_s
26
+ "ipc://#{path}"
27
+ end
28
+
29
+ end
30
+
31
+
17
32
  class << self
18
33
  # ZMTP connection class used for IPC-accepted/dialed peers.
19
34
  #
@@ -124,9 +139,30 @@ module OMQ
124
139
  end
125
140
 
126
141
 
142
+ # @param endpoint [String] e.g. "ipc:///tmp/my.sock" or "ipc://@abstract"
143
+ # @return [URI::Generic] the endpoint's URI; a {PathURI} for an
144
+ # abstract namespace name or a path +URI.parse+ rejects
145
+ #
146
+ def endpoint_uri(endpoint)
147
+ path = parse_path(endpoint)
148
+ return path_uri(path) if abstract?(path)
149
+
150
+ begin
151
+ URI.parse(endpoint)
152
+ rescue URI::InvalidURIError
153
+ path_uri(path)
154
+ end
155
+ end
156
+
157
+
127
158
  private
128
159
 
129
160
 
161
+ def path_uri(path)
162
+ PathURI.new("ipc", nil, nil, nil, nil, path, nil, nil, nil)
163
+ end
164
+
165
+
130
166
  # Connects to +path+ and hangs up. Raises ECONNREFUSED if nothing
131
167
  # listens there.
132
168
  #
@@ -147,6 +147,31 @@ module OMQ
147
147
  sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_RCVBUF, options.rcvbuf)
148
148
  end
149
149
  end
150
+
151
+
152
+ # A dial to a free local port can get that same port as its source
153
+ # and connect to itself (TCP simultaneous open). The handshake would
154
+ # then run against the socket itself. Nothing listens on that port,
155
+ # so this closes +sock+ and raises as refused, and the dialer retries.
156
+ #
157
+ # @param sock [Socket] a dialed socket
158
+ # @return [void]
159
+ # @raise [Errno::ECONNREFUSED] if +sock+ is connected to itself
160
+ #
161
+ def reject_self_connect!(sock)
162
+ local = sock.local_address
163
+ remote = sock.remote_address
164
+
165
+ return unless local.ip_unpack == remote.ip_unpack
166
+
167
+ begin
168
+ sock.close
169
+ rescue SystemCallError
170
+ # A failed close must not hide the refusal the dialer retries on.
171
+ end
172
+
173
+ raise Errno::ECONNREFUSED, "#{remote.inspect_sockaddr} connected to itself"
174
+ end
150
175
  end
151
176
 
152
177
 
@@ -179,7 +204,10 @@ module OMQ
179
204
  host, port = TCP.parse_endpoint(@endpoint)
180
205
  host = TCP.normalize_connect_host(host)
181
206
  sock = ::Socket.tcp(host, port, connect_timeout: TCP.connect_timeout(@engine.options))
207
+
208
+ TCP.reject_self_connect!(sock)
182
209
  TCP.apply_buffer_sizes(sock, @engine.options)
210
+
183
211
  @engine.handle_connected(IO::Stream::Buffered.wrap(sock), endpoint: @endpoint)
184
212
  end
185
213
 
data/lib/omq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OMQ
4
- VERSION = "0.30.0"
4
+ VERSION = "0.30.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.0
4
+ version: 0.30.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger