Skip to content

Jb/muxer ruby upgrade#7

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

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

Conversation

@skunkworker
Copy link
Copy Markdown
Collaborator

@skunkworker skunkworker commented Jun 1, 2026

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 😬

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