rabbitmq / rabbitmq-server

Open source RabbitMQ: core server and tier 1 (built-in) plugins
https://www.rabbitmq.com/
Other
12.14k stars 3.9k forks source link

Management UI: Fix internal_server_error args for put vhost failures #11585

Closed the-mikedavis closed 3 months ago

the-mikedavis commented 3 months ago

rabbit_mgmt_util:internal_server_error/4 expects an atom or binary and a string formattable term (~ts) as arguments but rabbit_mgmt_wm_vhost passes charlists and any term. This can cause a log formatter crash and an unexpected message in the management UI when attempting to add a vhost while a cluster is in a minority with Khepri enabled for example.

We can pass atoms for the Error parameter and binaries or strings for the Reason parameter to fix both issues.

the-mikedavis commented 3 months ago

Steps to reproduce on main:

There is a log formatter crash... ``` 2024-06-28T15:27:31.406820+00:00 error: FORMATTER CRASH: {"~ts~n~ts",["Timed out while waiting for the vhost to initialise",{error,timeout}]} 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> formatter_crashed: rabbit_logger_text_fmt 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> config: #{single_line => false,use_colors => false} 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> log_event: #{meta => 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> #{pid => <0.1292.0>,time => 1719588451406820, 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> gl => <0.688.0>, 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> domain => [rabbitmq]}, 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> msg => 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> {"~ts~n~ts", 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> ["Timed out while waiting for the vhost to initialise", 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> {error,timeout}]}, 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> level => error} 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> reason: {error,badarg, 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> [{io_lib,format, 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> ["~ts~n~ts", 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> ["Timed out while waiting for the vhost to initialise", 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> {error,timeout}]], 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> [{file,"io_lib.erl"},{line,189}]}, 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> {rabbit_logger_text_fmt,format,2, 2024-06-28 15:27:31.408992+00:00 [debug] <0.1292.0> [{file,"rabbit_logger_text_fmt.erl"},{line,15}]}]} ```

and the UI shows Management API returned status code 500 - {"error":[84,105,109,101,100,32,111,117,116,32,119,104,105,108,101,32,119,97,105,116,105,110,103,32,102,111,114,32,116,104,101,32,118,104,111,115,116,32,116,111,32,105,110,105,116,105,97,108,105,115,101],"reason":["error","timeout"]} in the error display.