Repository navigation
[Mocha] Fix RabbitMQ sends and publishes completing without the broker's confirmation - #10880
Merged
PascalSenn merged 3 commits intoNov 20, 2026
Merged
Conversation
This was referenced Nov 11, 2026
Merged
Contributor
Patch coverage93.0% of changed lines covered (174/187)
Uncovered changed lines (JSON){
"sha": "ff6f4e70fb58a185383143fbcbf0110778cd13d0",
"files": [
{ "path": "src/Mocha/src/Mocha.Transport.RabbitMQ/RabbitMQDispatcherHealthCheck.cs", "ranges": [[14, 15], [20, 22]] },
{ "path": "src/Mocha/src/Mocha.Transport.RabbitMQ/ThrowHelper.cs", "ranges": [[9, 9], [38, 38]] },
{ "path": "src/Mocha/src/Mocha.Transport.RabbitMQ/Connection/RabbitMQDispatcher.cs", "ranges": [[119, 120], [122, 123]] },
{ "path": "src/Mocha/src/Mocha.Transport.RabbitMQ/RabbitMQDispatchEndpoint.cs", "ranges": [[236, 237]] }
]
}Project coverage: 60.0% (329342/549108 lines) |
tobias-tengler
force-pushed
the
tte/mq-12-rabbitmq-publishing
branch
4 times, most recently
from
November 11, 2026 19:23
fa56b8f to
170ea2a
Compare
PascalSenn
force-pushed
the
tte/mq-12-rabbitmq-publishing
branch
from
November 12, 2026 22:07
170ea2a to
d4e935f
Compare
PascalSenn
force-pushed
the
tte/mq-12-rabbitmq-publishing
branch
from
November 13, 2026 15:21
d4e935f to
a047d4f
Compare
PascalSenn
force-pushed
the
tte/mq-12-rabbitmq-publishing
branch
from
November 19, 2026 23:59
a047d4f to
9c4ba77
Compare
PascalSenn
approved these changes
Nov 20, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
RabbitMQ dispatch lacks the promised publish deadline and retry/error behavior, while channel-slot handling during cancellation and recovery can trigger ChannelAllocationException.
4 open issues
What changed in this PR
Updates Mocha’s RabbitMQ dispatch path to wait for broker confirmations, building on the connection-manager and consumer-recovery work.
Changes:
- Adds pooled, confirm-enabled publisher channels, blocked-connection waits, and header-size validation.
- Integrates dispatcher health checks, named connections, role-specific logging, and configurable startup timeouts.
- Adds real-broker reliability, recovery, failover, and outbox tests, with updated operational documentation.
| File | Description |
|---|---|
| website/content/docs/mocha/transports/rabbitmq.md | Documents confirmations, recovery, logging, and startup behavior. |
| website/content/docs/mocha/migration/migrate-from-16-7-to-16-8.md | Describes dispatch and operational migration impacts. |
| website/content/docs/mocha/hosting.md | Explains readiness during consumer reattachment. |
| src/Mocha/test/Mocha.Transport.RabbitMQ3.Tests/Mocha.Transport.RabbitMQ3.Tests.csproj | Adds hosting support for health-check tests. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/RabbitMQTransportTests.cs | Uses topology snapshots and simplifies disposal checks. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/RabbitMQMessageEnvelopeFormatterTests.cs | Checks capacity for the client-added confirmation header. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/RabbitMQDispatchProvisioningTests.cs | Removes mock-based provisioning tests. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Mocha.Transport.RabbitMQ.Tests.csproj | Adds hosting support for health-check tests. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Helpers/TestManagers.cs | Adds dispatcher and transport-health helpers. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Helpers/RabbitMQFixture.cs | Removes the broker-wide connection-close helper. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Helpers/RabbitMQClusterFixture.cs | Provides a three-node broker cluster for failover tests. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Descriptors/RabbitMQDescriptorTests.cs | Tests startup-timeout validation. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Connection/RabbitMQLifecycleTests.cs | Tests pending rents, disposal, and consumer registration. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Connection/RabbitMQDispatcherTests.cs | Removes mock-based dispatcher tests. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Connection/RabbitMQDispatcherIntegrationTests.cs | Tests channel limits, isolation, recovery, and disposal. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Connection/RabbitMQConnectionManagerBaseTests.cs | Removes tests for the deleted connection-manager base. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/SilentEndpointRecoveryTests.cs | Tests recovery from an unresponsive connection endpoint. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/QuorumFailoverTests.cs | Tests quorum failover and unacknowledged-message redelivery. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/PublishIsolationTests.cs | Tests cancellation, oversized messages, headers, and broker alarms. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/PublishingReliabilityTests.cs | Tests broker rejections and publish-failure isolation. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/PublishingConcurrencyTests.cs | Tests concurrent dispatch and recovery after cancellation. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/PublisherRecoveryTests.cs | Tests blocked, offline, cancelled, and restarted publishers. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/HealthCheckTests.cs | Tests blocked dispatcher and consumer-capacity health reports. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/FaultHandlingTests.cs | Verifies handler completion before continuing the test. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/ConnectionStartupTests.cs | Tests startup retries, refusals, timeouts, and connection names. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/ConnectionRecoveryTests.cs | Uses scoped fault injection and explicit recovery assertions. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/BrokerRecoveryTests.cs | Tests broker outages, credential changes, and resource cleanup. |
| src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/__snapshots__/RabbitMQTransportTests.Describe_Should_ListExchangesQueuesAndBindings_When_EventHandlerRegistered.snap | Records the expected transport topology. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/Mocha.EntityFrameworkCore.Postgres.Tests.csproj | Adds RabbitMQ transport and broker-fixture references. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/Broker/PostgresOutboxBrokerTests.cs | Tests outbox retention and delivery against RabbitMQ. |
| src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/Broker/OutboxBrokerFixture.cs | Provides isolated databases, brokers, and fault controls. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/ThrowHelper.cs | Centralizes new dispatch and configuration exceptions. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/RabbitMQMessagingTransport.cs | Wires dispatcher connection management and startup settings. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/RabbitMQMessageEnvelopeFormatter.cs | Reserves capacity for the confirmation sequence header. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/RabbitMQDispatcherHealthCheck.cs | Reports unavailable or blocked dispatcher connections. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/RabbitMQDispatchEndpoint.cs | Publishes through leases and validates header-frame size. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/MessageBusBuilderExtensions.cs | Registers dispatcher health checks. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Extensions/RabbitMQTransportConfigurationExtensions.cs | Validates the supported startup-timeout range. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Descriptors/RabbitMQMessagingTransportDescriptor.cs | Implements the fluent startup-timeout setting. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Descriptors/IRabbitMQMessagingTransportDescriptor.cs | Exposes the startup-timeout contract. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Connection/RabbitMQDispatcherOptions.cs | Defines publisher-channel and channel-open limits. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Connection/RabbitMQDispatcher.cs | Manages confirm-enabled channel leases and connection access. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Connection/RabbitMQConnectionScopedLogger.cs | Selects connection names and logging categories by role. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Connection/RabbitMQConnectionManagerOptions.cs | Enables record-based option copying. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Connection/RabbitMQConnectionManagerBase.cs | Removes the legacy connection-manager base. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Connection/ChannelLease.cs | Tracks channel ownership and reuse eligibility. |
| src/Mocha/src/Mocha.Transport.RabbitMQ/Configurations/RabbitMQTransportConfiguration.cs | Adds transport-level startup-timeout configuration. |
Review effort: Balanced
Comment on lines
+73
to
+75
| if (!_slots.Reader.TryRead(out var idle) && Interlocked.Increment(ref _createdSlots) > MaxSlots) | ||
| { | ||
| Interlocked.Decrement(ref _createdSlots); |
Comment on lines
+143
to
+144
| _ = _connectionManager.CloseChannelAsync(lease.Channel); | ||
| _slots.Writer.TryWrite(null); |
|
|
||
| var envelope = context.Envelope ?? throw ThrowHelper.EnvelopeRequired(); | ||
| var dispatcher = transport.Dispatcher; | ||
| var cancellationToken = context.CancellationToken; |
Comment on lines
+52
to
+56
| catch (PublishException) | ||
| { | ||
| await dispatcher.ReturnChannelAsync(channel); | ||
| // The broker answered with a rejection or a return. | ||
| lease.IsReusable = true; | ||
| throw; |
…lish A publish rents a channel, declares its topology once, publishes and waits for the confirmation of the broker. The transport no longer sends a failed message again and has no publish timeout of its own: a publish waits until the cancellation token of the caller is cancelled. - The dispatcher keeps its channels as slots in one queue. A slot is an idle channel or a free place for a new one, and at most 100 exist. - A channel lease is disposable, gives its channel back on dispose and records whether the channel can be used again. - A rejected message throws the PublishException of the client at once. - A channel open that the broker does not answer because it blocks the connection waits until the broker reads again. - PublishTimeout, the publish retries, the stalled publish watchdog and the publish log entries are removed. - The dispatcher exposes IsBlocked in place of its connection manager.
PascalSenn
force-pushed
the
tte/mq-12-rabbitmq-publishing
branch
from
November 20, 2026 15:00
3b89462 to
56cef80
Compare
michaelstaib
added a commit
to michaelstaib/graphql-platform
that referenced
this pull request
Nov 23, 2026
* [Website] Fix HTTP response formatter docs for the v16 API (ChilliCream#10951) * Fix the release failing while installing k6 for the Fusion PGO profile (ChilliCream#10952) * Fix the AspNetCore tests failing to build for .NET 8 (ChilliCream#10962) * Rename the Draft20260903 transport version to September2026 (ChilliCream#10963) * [Fusion] Match fully reused entities on XxHash3 keys and copy producer rows once (ChilliCream#10941) * Deprecate the Draft20230127 transport version (ChilliCream#10964) * [Website] Update benchmark results (ChilliCream#10965) * Enable empty selection sets by default (ChilliCream#10971) * Add empty selection set support to StrawberryShake (ChilliCream#10972) * Persist GitHub CLI login across container rebuilds (ChilliCream#10974) * Fix the Green Donut documentation link in the README (ChilliCream#10973) * [Fusion] Fix missing operation plan metadata in YAML test snapshot diffs (ChilliCream#10975) * Use OIDC for Docker Hub login (ChilliCream#10976) * [Website] Update benchmark results (ChilliCream#10977) * Coordinate commercial builds and releases (ChilliCream#10970) * Parallelize repository preparation in prepare-release.sh (ChilliCream#10978) * Remove the cloud platform update from the release workflow (ChilliCream#10979) * [Fusion] Reduce allocations on the error path (ChilliCream#10981) * [Fusion] Fix missing errors for nested shared value types (ChilliCream#10967) Co-authored-by: tobias-tengler <45513122+tobias-tengler@users.noreply.github.com> * [Fusion] Fix null propagation for required list items (ChilliCream#10983) * [Fusion] Fix lookup error paths (ChilliCream#10986) * [Fusion] Fix missing errors for null required object list items (ChilliCream#10989) * [Fusion] Fix late subgraph results dropping siblings of nulled objects (ChilliCream#10990) * [Fusion] Fix late subgraph results reporting false list length mismatches (ChilliCream#10991) * [Fusion] Fix results with more than 32,767 source documents throwing (ChilliCream#10998) * [Website] Update npm dependencies to clear advisories (ChilliCream#11002) * Update .NET SDK to 11.0.100 (ChilliCream#11004) * [Fusion] Reduce allocations when forwarding errors (ChilliCream#11003) * [Nitro CLI] Accept Apollo persisted query manifests for client upload/validate (ChilliCream#11005) * [Mocha] Fix dispatch race during endpoint startup (ChilliCream#11006) * [Mocha] Fix ExponentialBackoff returning the same delay once it reaches the maximum (ChilliCream#10870) * [Mocha] Log receive failures and circuit breaker state changes, and fix the conversation ID of the receive span (ChilliCream#10871) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Fix RequestAsync waiting for a dispatch that outlasts the response timeout (ChilliCream#10872) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Report unhealthy transports in the message bus health check and add a timeout (ChilliCream#10873) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Start reply endpoints first, stop them last, and finish cleanup when a stop is cancelled (ChilliCream#10874) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Fix the Postgres outbox using up the attempts of a message while the transport is unavailable (ChilliCream#10875) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Fix scheduled messages using up their attempts while the transport is unavailable (ChilliCream#10876) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Prepare the RabbitMQ transport: internal connection types, RabbitMQ.Client 7.2.2, provisioning with the connection, queue defaults (ChilliCream#10877) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Add the RabbitMQ connection manager and failure classification (ChilliCream#10878) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Fix RabbitMQ consumers not attaching again after a channel or connection loss (ChilliCream#10879) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Fix RabbitMQ sends and publishes completing without the broker's confirmation (ChilliCream#10880) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Fix messages for a missing RabbitMQ queue or exchange being dropped (ChilliCream#10881) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Fix RabbitMQ requests being sent before the reply consumer is attached (ChilliCream#10882) Co-authored-by: Pascal Senn <pascal@chillicream.com> * [Mocha] Move the outbox and scheduler dispatch intervals into their options (ChilliCream#11007) * Update the .NET 11 packages to the GA release (ChilliCream#11008) * [Mocha] Fix scalar JSON bodies being cut to their last byte when a stored envelope is read (ChilliCream#11014) * [Mocha] Fix generated registrations for message types found at publish and send call sites (ChilliCream#11013) * [Mocha] Fix docs that name APIs and delivery guarantees Mocha does not have (ChilliCream#11015) * [Mocha] Add UseDispatch, UseReceive and UseConsume to the message bus host builder (ChilliCream#11020) * Update Aspire and WebUtilities to their patched releases (ChilliCream#11021) * Set a 7-day NuGet minimum publish age, exempting ChilliCream packages (ChilliCream#11023) * Replace custom test loggers and clocks with Microsoft testing utilities (ChilliCream#11025) * [Mocha] Fix saga replies being lost when the sending instance stops (ChilliCream#11022) * [Fusion] Fix PGO profile handoff to commercial builds (ChilliCream#11027) * [Fusion] Fix a source schema result staying unreleased when the result callback throws in an alias batch (ChilliCream#11009) * Fix the fixed-size array pool reserving slots for its largest level up front (ChilliCream#11011) * Skip unescaping and hashing request documents the parser has seen before (ChilliCream#11010) * Fix Postgres subscription dispose leaking a connection or hanging (ChilliCream#11026) * [Mocha] Fix saga replies being discarded when they arrive before the saga state is saved (ChilliCream#11028) * Snapshot small request feature collections without a frozen dictionary (ChilliCream#10942) * Fix the cache dropping an entry when a duplicate of its key is evicted (ChilliCream#11039) * Write the accessed flag of a cache entry only when it is not set (ChilliCream#11040) * [Fusion] Call Apollo Federation entity lookups without nested async iterators (ChilliCream#11041) * [Fusion] Read source schema results with the shape that their operation expects (ChilliCream#11043) * [Website] Add Mocha comparison pages and migration guides (ChilliCream#11024) * [Fusion] Keep the scratch state of entity lookups per request and build error variable sets on demand (ChilliCream#11042) * [Fusion] Reference the closed options services of the gateway so Native AOT binaries contain them (ChilliCream#11012) * [Fusion] Set the operation planner version to 2.13.0 * [Fusion] Update the plan snapshots of the deferred tests to the snapshot format of main * [Fusion] Fix a sibling field being lost when a late source result has errors below a nulled position --------- Co-authored-by: Glen <glen.84@gmail.com> Co-authored-by: Tobias Tengler <45513122+tobias-tengler@users.noreply.github.com> Co-authored-by: Faris Basha TM <72191505+farisbasha@users.noreply.github.com> Co-authored-by: vbornand <vbo@netswipe.ch> Co-authored-by: PascalSenn <senn.pasc@gmail.com> Co-authored-by: Pascal Senn <pascal@chillicream.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

A send or publish through the RabbitMQ transport completed when the message was written to the connection, and a message that RabbitMQ did not accept was lost without an error. This pull request is the publish side of the RabbitMQ rework, plus what needs both sides.
Changes
PublishTimeout(new setting, two minutes by default, infinite allowed) bounds the whole call: the wait for a connection, the wait for a free channel and every retry. After it the call throwsTransportUnavailableException.InvalidOperationException, because the queues that accepted it have it. A message that makes the broker close the channel fails with the reply code and text of the broker and is not sent again. Headers that do not fit into one frame fail before the write.RabbitMQConnectionManagerBaseis deleted.StartTimeout(new setting, two minutes by default): how long the start retries while RabbitMQ cannot be reached. The start fails at once when the broker refuses the credentials, the access or the topology.HealthFailureReason: dispatcher connection unavailable or blocked, consumer connection unavailable, a consumer that is not attached or waits for handlers of a lost channel.Mocha.Transport.RabbitMQ.Dispatcher, and the dispatcher connection has a name.Behavior after this pull request
PublishTimeout.TransportUnavailableExceptionor outlastsDispatchTimeout.PostgresOutboxBrokerTestsruns the outbox against a real broker.main: a message for a queue that does not exist is confirmed and dropped ([Mocha] Fix messages for a missing RabbitMQ queue or exchange being dropped #10881), and a request does not wait for its reply consumer ([Mocha] Fix RabbitMQ requests being sent before the reply consumer is attached #10882).For the review
Confirms without the parts around them would be worse than
main: without the deadline a publish waits without bound, without the wait on a blocked connection the outbox adds a copy perDispatchTimeoutduring an alarm, and without the rule for rejected events a retry copies the event into the queues that accepted it. That is why confirms, the pool, the deadline, the retry, the blocked wait and the rejection rule are one pull request. A reading order:PublisherLease.csandPublisherChannelPool.cs.PublishDeadline.cs.RabbitMQDispatcher.cs:RentChannelAsync,Return,GetPool,DisposeAsync.RabbitMQDispatcher.Publishing.cs:StartPublish,FinishPublish,CanRetry, the check for a stalled publish, the log helpers.RabbitMQDispatchEndpoint.cs:DispatchAsync,PrepareChannelAsync,PublishOnceAsync,EnsureProvisionedAsync,EnsureHeadersFit.PublishTimeoutandStartTimeoutin the configuration and the descriptor.HealthFailureReasoninRabbitMQMessagingTransport.cs.The deleted base class and the three deleted mock-based test files (
RabbitMQConnectionManagerBaseTests.cs,RabbitMQDispatcherTests.cs,RabbitMQDispatchProvisioningTests.cs, 897 lines) need no reading.Tests, in a useful order:
RabbitMQDispatcherIntegrationTests,PublishingReliabilityTests,PublishIsolationTests,PublisherRecoveryTests,PublishingConcurrencyTests,BrokerRecoveryTests,RabbitMQLifecycleTests,ConnectionRecoveryTests,ConnectionStartupTests,HealthCheckTests,QuorumFailoverTests(a cluster of brokers),PostgresOutboxBrokerTests.Docs:
rabbitmq.md("Publisher confirms", the dispatcher half of "Recovery logs", "A message is handled twice", "Startup connection timeout"), the RabbitMQ paragraph ofhosting.md, and ten entries in the migration guide.Part 12 of 14 of the stack that replaces #10543. It builds on #10879, #10878, #10875 (
TransportUnavailableException), #10873 (HealthFailureReason), #10871 (BeginMessageScope) and #10870.