Repository navigation
Description
Describe the bug
Summary
Importing a definitions file exported for a single virtual host into
POST /api/definitions is rejected on purpose: its queues, exchanges and
bindings have no vhost field, and the
HTTP API reference points to
POST /api/definitions/{vhost}. That decision is correct.
The problem is how the rejection is delivered. The orphan check throws just
before the try that normalises {error, E} into {error, format(E)} in
apply_defs/3, so the exception bypasses both that normalisation and the
handler's {error, E} -> bad_request(...) branch. The request process exits and
the client gets 500 with an empty body, while the other rejections this
endpoint performs return 400 with a reason (measured below).
Environment
- RabbitMQ 4.4.1, official
rabbitmq:4.4.1-managementimage - Erlang/OTP 29 [erts-17.1.2],
erlang_version29.1.3 - Ubuntu 26.04.1 LTS
- No client library involved: plain
curl - Reproduced on 4.4.1; the same code is on
mainat e5fcd1d
Reproduction steps
Steps to reproduce
Start a node with the management plugin and an administrator user:
docker run -d --name rmq --user rabbitmq -p 15672:15672 \
-e RABBITMQ_DEFAULT_USER=t -e RABBITMQ_DEFAULT_PASS=t \
rabbitmq:4.4.1-management
Then import a vhost-scoped document into the cluster-wide endpoint:
// bash
curl -i -u t:t -H 'content-type: application/json' \
-d '{"queues":[{"name":"q1","durable":true}]}' \
localhost:15672/api/definitions
### Expected behavior
### Expected
`400` with the reason, like the other documents this endpoint cannot import:
```json
{"error":"bad_request","reason":"invalid_definitions_file"}Actual
500 Internal Server Error, empty body; nothing is imported
(GET /api/queues/%2F/q1 returns 404). The log shows the request process
exiting with {{nocatch,{error,invalid_definitions_file}}} from
rabbit_definitions:apply_defs/3 (line 554): the exception was never caught.
Additional context
Cause
deps/rabbit/src/rabbit_definitions.erl:549-557 runs the orphan check before the
try at line 559, whose catch {error, E} -> {error, format(E)} (line 592) is
what turns import errors into the return value its spec declares
('ok' | {error, term()}). The throw therefore bypasses that normalisation, and
the handler's {error, E} branch at
deps/rabbitmq_management/src/rabbit_mgmt_wm_definitions.erl:350 is never reached
for this error, although it does handle the other import failures.
Fix
Moving the check inside the existing try would make apply_defs/3 return
{error, <<"invalid_definitions_file">>}, which the handler already renders as
400. Boot-time imports are unaffected: load_from_single_file/1 returns the
error and rabbit.erl turns a non-ok result into a throw during startup.
I can open a PR with the fix and a regression test in rabbit_mgmt_http_SUITE if
that is the preferred way to proceed.
If the 500 is intentional for this input, the empty body is still a defect: the
reason is known to the server, is recorded in the log, and is what a client needs
in order to use POST /api/definitions/{vhost}.
Activity
Definitions: store the content hash only after a successful import
Return a bad request for vhost definitions imported cluster-wide
mkuratczyk commentedon Nov 27, 2026
Thanks for the report. Addressed in #18518