{"record":{"id":"e6ef72dbd94bad91","repo":"nestjs/nest","slug":"rmq-broker-has-blocked-the-connection-flow-contro-e6ef72","errorCode":null,"errorMessage":"RMQ broker has blocked the connection (flow control). Reason: ${reason}","messagePattern":"RMQ broker has blocked the connection \\(flow control\\)\\. Reason: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/microservices/server/server-rmq.ts","lineNumber":196,"sourceCode":"\n  private registerConnectListener() {\n    this.server!.on(RmqEventsMap.CONNECT, (err: any) => {\n      this._status$.next(RmqStatus.CONNECTED);\n    });\n  }\n\n  private registerDisconnectListener() {\n    this.server!.on(RmqEventsMap.DISCONNECT, (err: any) => {\n      this._status$.next(RmqStatus.DISCONNECTED);\n      this.logger.error(DISCONNECTED_RMQ_MESSAGE);\n      this.logger.error(err);\n    });\n  }\n\n  private registerBlockedListener() {\n    this.server!.on(RmqEventsMap.BLOCKED, ({ reason }: { reason: string }) => {\n      this._status$.next(RmqStatus.BLOCKED);\n      this.logger.warn(BLOCKED_RMQ_MESSAGE(reason));\n    });\n  }\n\n  private registerUnblockedListener() {\n    this.server!.on(RmqEventsMap.UNBLOCKED, () => {\n      this._status$.next(RmqStatus.UNBLOCKED);\n      this.logger.log(UNBLOCKED_RMQ_MESSAGE);\n    });\n  }\n\n  public async setupChannel(channel: Channel, callback: Function) {\n    const noAssert =\n      this.getOptionsProp(this.options, 'noAssert') ??\n      this.queueOptions.noAssert ??\n      RMQ_DEFAULT_NO_ASSERT;\n\n    let createdQueue: string;\n","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/nestjs/nest/blob/dd75d7bd8c5e88048587e6768d36eb695f3e7a25/packages/microservices/server/server-rmq.ts#L178-L214","documentation":"The RMQ transport server (ServerRMQ) also publishes: every reply to a requesting client goes back through the broker. When RabbitMQ raises a memory or disk alarm it blocks the server's connection; the BLOCKED listener pushes RmqStatus.BLOCKED into the server's status stream and logs this warning with the broker-supplied reason. While blocked, the server keeps consuming but its replies (sendMessage to replyTo queues) are held back, so RPC callers see rising latency until UNBLOCKED fires.","triggerScenarios":"A microservice created with Transport.RMQ whose reply traffic hits a broker resource alarm: connection.blocked with reason 'memory' or 'disk' is emitted on the server's connection. Typically the alarm is caused by queue growth from slow consumers, broker memory pressure, or low disk on the broker node — not necessarily by this service itself.","commonSituations":"Broker containers with small memory limits under load; a burst of RPC traffic piling up messages (replies and other queues share the node budget); another client on the same node triggering a node-wide alarm that blocks all publishing connections; disk pressure on the broker host.","solutions":["Resolve the alarm broker-side: `rabbitmqctl status` / `rabbitmq-diagnostics alarms`, free disk, add memory, or raise vm_memory_high_watermark / disk_free_limit with real headroom.","Keep consumer lag bounded (scale handler instances, finite prefetch) so the node stops drifting into alarms.","If you hold the server instance (or via the microservice returned by connectMicroservice), subscribe to its `status` observable to expose BLOCKED/UNBLOCKED in health checks and metrics.","Give RPC callers timeouts so a blocked broker surfaces as errors instead of hangs, and alert on the BLOCKED status."],"exampleFix":"# before: defaults trip alarms early (rabbitmq.conf)\n# vm_memory_high_watermark.relative = 0.4\n# disk_free_limit.absolute = 50MB\n\n# after: headroom matched to the node/container\nvm_memory_high_watermark.relative = 0.6\ndisk_free_limit.absolute = 2GB","handlingStrategy":"fallback","validationCode":"# exit non-zero while any resource alarm is active on the broker\n# (alarms are exactly what puts ServerRMQ connections into BLOCKED)\nrabbitmqctl eval 'rabbit_alarm:get_alarms().' | grep -q '^\\[\\]' \\\n  || echo 'broker alarmed: RMQ connections will be blocked until it clears'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Monitor broker alarms and node memory/disk; alert before the watermark trips","Expose the server's status observable in readiness probes so BLOCKED surfaces in orchestration","Give RPC callers explicit timeouts so a blocked broker fails fast instead of hanging","Keep queues drained (scale consumers, finite prefetch) so reply traffic never pushes the node into an alarm"],"tags":["rabbitmq","amqp","flow-control","resource-alarm","microservices"],"backgroundTag":"rabbitmq-connection-blocked-flow-control","analyzedSha":"dd75d7bd8c5e88048587e6768d36eb695f3e7a25","analyzedAt":"2026-08-21T19:39:39.867Z","contentChangedAt":"2026-08-21T19:39:39.867Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}