Skip to content

Commit 30c0569

Browse files
dumbbellikavgo
authored andcommitted
rabbitmq-run.mk: Stop node in start-background-broker in case of error
[Why] The CLI sometimes crashes early because it fails to configure the Erlang distribution. Because we use two CLI commands to watch the start of RabbitMQ, if one of them fails, the Make recipe will exit with an error, leaving the RabbitMQ node running. [How] We use a shell trap to stop the node if the shell is about to exit with an error. While here, we retry the `await_startup` CLI command several times because this is the one failing the most. This is until the crash is understood and a proper fix is committed.
1 parent 2d6bf7f commit 30c0569

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

deps/rabbit_common/mk/rabbitmq-run.mk

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,13 @@ start-background-broker: node-tmpdir $(DIST_TARGET)
323323
$(BASIC_SCRIPT_ENV_SETTINGS) \
324324
$(RABBITMQ_SERVER) \
325325
$(REDIRECT_STDIO) &
326+
trap 'test "$$?" = 0 || $(MAKE) stop-node' EXIT && \
326327
ERL_LIBS="$(DIST_ERL_LIBS)" \
327328
$(RABBITMQCTL) -n $(RABBITMQ_NODENAME) wait --timeout $(RMQCTL_WAIT_TIMEOUT) $(RABBITMQ_PID_FILE) && \
328-
ERL_LIBS="$(DIST_ERL_LIBS)" \
329-
$(RABBITMQCTL) --node $(RABBITMQ_NODENAME) await_startup
329+
for i in $$(seq 1 10); do \
330+
ERL_LIBS="$(DIST_ERL_LIBS)" $(RABBITMQCTL) -n $(RABBITMQ_NODENAME) await_startup || sleep 1; \
331+
done && \
332+
ERL_LIBS="$(DIST_ERL_LIBS)" $(RABBITMQCTL) -n $(RABBITMQ_NODENAME) await_startup
330333

331334
start-rabbit-on-node:
332335
$(exec_verbose) ERL_LIBS="$(DIST_ERL_LIBS)" \

0 commit comments

Comments
 (0)