Skip to content

rabbitmq-diagnostics status: handle nil vm_memory_high_watermark#15678

Closed
jalju0804 wants to merge 1 commit intorabbitmq:mainfrom
jalju0804:fix/formatted-watermark-nil-status-command
Closed

rabbitmq-diagnostics status: handle nil vm_memory_high_watermark#15678
jalju0804 wants to merge 1 commit intorabbitmq:mainfrom
jalju0804:fix/formatted-watermark-nil-status-command

Conversation

@jalju0804
Copy link
Copy Markdown
Contributor

@jalju0804 jalju0804 commented Mar 9, 2026

Fixes #15679

Why

When a node is in maintenance mode, the vm_memory_monitor GenServer is not running. rabbit_misc:filter_exit_map/2 in rabbit.erl silently drops the :vm_memory_high_watermark key from the status result keyword list when the process call exits. Keyword.get(result, :vm_memory_high_watermark) therefore returns nil, and nil |> Memory.formatted_watermark/1 crashes with a FunctionClauseError because no clause matches nil.

This crash affects both rabbitmq-diagnostics status and rabbitmqctl status when run against a node that has been put into maintenance mode.

Stack Trace

** (FunctionClauseError) no function clause matching in RabbitMQ.CLI.Core.Memory.formatted_watermark/1
    lib/rabbitmq/cli/core/memory.ex:57: RabbitMQ.CLI.Core.Memory.formatted_watermark(nil)
    lib/rabbitmq/cli/ctl/commands/status_command.ex:274: RabbitMQ.CLI.Ctl.Commands.StatusCommand.result_map/1
    lib/rabbitmq/cli/ctl/commands/status_command.ex:65: RabbitMQ.CLI.Ctl.Commands.StatusCommand.output/2
    lib/rabbitmqctl.ex:174: RabbitMQCtl.maybe_run_command/3

Changes

  • memory.ex: add a nil clause to formatted_watermark/1 that returns nil, so the JSON formatter path completes without crashing.
  • status_command.ex: add a nil branch to the readable_watermark_setting case expression so the text formatter outputs (unknown) instead of crashing.

This is the same crash location as #2964, but triggered by nil instead of {:relative, float}.

Checklist

  • I have signed the CLA (https://github.com/rabbitmq/cla)
  • I have read CONTRIBUTING.md
  • I have added tests that prove my fix is effective
  • If relevant, I have added this change to release-notes/

When a node is put into maintenance mode (or vm_memory_monitor is
otherwise unavailable), rabbit_misc:filter_exit_map/2 in rabbit.erl
silently drops the :vm_memory_high_watermark key from the status
result. This causes Keyword.get/2 to return nil, which is then piped
into formatted_watermark/1. Since no function clause matched nil,
the command crashed with a FunctionClauseError.

Add a nil clause to formatted_watermark/1 in Memory that returns nil,
and handle nil in the readable_watermark_setting case expression in
StatusCommand so the text formatter outputs "(unknown)" instead of
crashing.

Fixes the Kolla-Ansible upgrade task failure:
  rabbitmq-diagnostics --formatter json status -n rabbit
  Error: :function_clause
  RabbitMQ.CLI.Core.Memory.formatted_watermark/1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@michaelklishin
Copy link
Copy Markdown
Collaborator

Thank you. Your proposed solution is on the right track. #15680 extends it a bit more.

@michaelklishin
Copy link
Copy Markdown
Collaborator

Accepted with a few exceptions in #15680.

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.

rabbitmq-diagnostics status crashes with FunctionClauseError when vm_memory_high_watermark is unavailable

2 participants