fix(kafka): use sentinel file to eliminate starter-script race condition (#11682) - #11957
Draft
klouds27 wants to merge 1 commit into
Draft
fix(kafka): use sentinel file to eliminate starter-script race condition (#11682)#11957klouds27 wants to merge 1 commit into
klouds27 wants to merge 1 commit into
Conversation
…ion (testcontainers#11682) copyFileToContainer writes the startup script into the container over a Docker API call. On busy hosts the wait loop can detect the file the moment its inode is created, before the write completes, and attempt to execute an incomplete file. This produces ETXTBSY and exit code 126. The fix adds a sentinel file (STARTER_SCRIPT + ".ready") that is touched via execInContainer only after copyFileToContainer returns. The wait loop now checks for the sentinel instead of the script itself, so execution cannot begin until the script is fully written. Applied to KafkaHelper, org.testcontainers.kafka.KafkaContainer, org.testcontainers.kafka.ConfluentKafkaContainer, and the deprecated org.testcontainers.containers.KafkaContainer. Signed-off-by: klouds27 <adalwolf@gmail.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.
The Kafka containers start the broker by writing a startup script into the container via
copyFileToContainer, then executing it with a shell loop that polls for the file. Because the loop checks only for file existence, it can detect the script the instant its inode is created and attempt to execute it before the write completes. On busy hosts this producesText file busy(ETXTBSY) and a container exit code of 126.This was confirmed in #11682 by the reporter and a second commenter. The suggestion of checking file size with
[ -s file ]was also tested and failed for the same reason: size becomes non-zero before the write finishes.The fix introduces a sentinel file (
/tmp/testcontainers_start.sh.ready) that is created viaexecInContainer("touch", ...)only aftercopyFileToContainerreturns. The wait loop now polls for the sentinel instead of the script itself. BecausecopyFileToContainercompletes fully before the sentinel is touched, the loop cannot proceed until the script is both fully written and closed.The change is applied consistently to all affected containers:
org.testcontainers.kafka.KafkaHelper(shared COMMAND constant),org.testcontainers.kafka.KafkaContainer,org.testcontainers.kafka.ConfluentKafkaContainer, and the deprecatedorg.testcontainers.containers.KafkaContainer.Fixes #11682