Skip to content

Jb/muxer ruby upgrade#7

Closed
skunkworker wants to merge 15 commits into
mxenabled:masterfrom
skunkworker:jb/muxer_ruby_upgrade
Closed

Jb/muxer ruby upgrade#7
skunkworker wants to merge 15 commits into
mxenabled:masterfrom
skunkworker:jb/muxer_ruby_upgrade

Conversation

@skunkworker

@skunkworker skunkworker commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Taking over work from #2

# Create a subscription but reset the pending queue to use a central pending queue.
# NOTE: This is a potential race condition. Chances of the round-trip message to an
# existing queue before this queue swap happens seems extremely low, but possible.
sub.pending_queue = @pending_queue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't love this, but I think it's probably fine. We could drop msgs here if ruby performs a long and unhealthy GC between these lines. While not probable, it's possible this happens coming out of a maintenance mode when you're not warm (jruby JITs) and requests are thrashing. But, I don't think there's a clean way to plumb, and it's not worth a thread local context hack...

# Example:

def with_pending_queue(pending_queue:)
  Thread.current[:pending_queue] = @pending_queue 

  yield
ensure
  Thread.current[:pending_queue] = nil
end

module SomethingHorrible
  def initialize
    super 

    @pending_queue = Thread.current[:pending_queue] if Thread.current[:pending_queue].present?
  end
end

class NATS::IO::Subscription
  prepend SomethingHorrible
end

...

with_pending_queue(pending_queue: @pending_queue)
  sub = @nats.subscribe(name, queue: name)

  assert sub.pending_queue == @pending_queue 
end

But... that's pretty nasty 😬

skunkworker added a commit to skunkworker/protobuf-nats that referenced this pull request Jun 24, 2026
- Bounded + jittered client retry (#1): configurable PB_NATS_CLIENT_MAX_RETRIES
  and PB_NATS_CLIENT_RECONNECT_DELAY_SPLAY_LIMIT; the reconnect sleep now adds
  random jitter so a fleet doesn't reconnect in lockstep.
- ConnectionPool::TimeoutError is now retryable (mxenabled#9) -- subscription-pool
  exhaustion during a reconnect is transient, not an RPC_ERROR.
- connection_options now forwards only nats-pure-recognized keys (mxenabled#7); app-level
  settings are read via their own accessors and no longer leak into connect.
- YAML config uses safe_load(aliases: true) instead of unsafe_load (mxenabled#8).
- Documented the client response_timeout <-> server handler_overdue coupling and
  the new client retry knobs in the README (mxenabled#5).

Specs updated; full suite 183 examples / 0 failures.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants