Repository navigation
Conversation
The container entrypoint killed the broker mid-shutdown on every `docker stop` or pod termination, leaving KahaDB unclean and forcing journal recovery on the next start. Two problems combined: 1. entrypoint.sh traps TERM/INT and waits on the backgrounded broker. A trapped signal makes `wait` return immediately (status > 128), so the script reached `exit` while the broker was still running its shutdown hook. As PID 1, that stops the container and the runtime SIGKILLs the broker. Wait a second time after the trap fires, guarded by a liveness check because waiting on an already reaped child returns 127, and propagate the broker's real exit status. 2. `activemq console` runs the JVM as `sh -c "java ..."` without `exec` inside the string. Where /bin/sh is dash (Debian/Ubuntu images), dash forks the JVM instead of exec-ing it, so the entrypoint's SIGTERM hit the sh wrapper, which died without forwarding it and left the JVM orphaned. Add `exec` inside the sh -c string for the foreground branch of invokeJar so the JVM replaces the shell and receives the signal directly. Fixes apache#2768 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2768
Problem
Every
docker stop/ Kubernetes pod termination of the official image ended in an unclean KahaDB shutdown, regardless of the grace period. The broker was SIGKILLed while its shutdown hook was still running, so the next start had to recover the journal.Two things combined:
entrypoint.sh: a trapped signal makeswaitreturn immediately with a status above 128. The script then reachedexitwhile the broker was still shutting down, and as PID 1 its exit stops the container.bin/activemq:consoleruns the JVM assh -c "java ..."without anexecinside the string. On dash (Debian/Ubuntu-based images) the JVM is forked as a child of thatsh. The entrypoint's SIGTERM reached only thesh, which died without forwarding it, leaving the JVM orphaned.Note: the suggestion in the issue that
activemq consoleexecs the JVM doesn't hold on these images, so just a secondwaitis not enough, and neither would beexec "$@".Changes
assembly/src/docker/entrypoint.sh: wait a second time after the trap fires so PID 1 stays alive until the broker exits, and exit with the broker's real status. The second wait is guarded bykill -0, since waiting on an already reaped child returns 127.assembly/src/release/bin/activemq: addexecinside thesh -cstring in the foreground branch ofinvokeJar, so the JVM replaces the shell and receives SIGTERM directly. The exit status is unchanged. The change also applies to non-Docker use of this branch.Verification
Built images with podman, loaded 5000 persistent messages, ran
podman stop -t 60, restarted on the same data volume, and compared. The entrypoint was traced withbash -x.sh -c "java ..."(JVM is its child)prior unclean shutdown, 4967 ops replayedsh -c "java ..."prior unclean shutdown, 4978 ops replayedjavaWith both changes, the trace shows
kill -TERMfollowed by the secondwait, and the broker's shutdown completes before the script exits. Exit code is 143, which is the JVM's normal status for SIGTERM.Not tested: Kubernetes, or images where
/bin/shis not dash.🤖 Generated with Claude Code