Avoid 'Text file busy' race when starting KafkaContainer#11769
Open
singhvishalkr wants to merge 1 commit intotestcontainers:mainfrom
Open
Avoid 'Text file busy' race when starting KafkaContainer#11769singhvishalkr wants to merge 1 commit intotestcontainers:mainfrom
singhvishalkr wants to merge 1 commit intotestcontainers:mainfrom
Conversation
Fixes testcontainers#11682. The container's command waits for /tmp/testcontainers_start.sh to appear, then exec's it. containerIsStarting writes the script via a single Container Archive PUT. On busy hosts the directory entry becomes visible before the docker engine has released the writer, and the immediate exec fails with ETXTBSY (exit 126). Switch to a two-file handshake: write the starter script first, then a separate /tmp/testcontainers_start.ready marker. The wait loop polls the marker instead of the script. By the time the second copyFileToContainer returns, the script's writer is fully closed, so the subsequent exec is safe. The marker file is never executed, so its own copy can race with the directory listing harmlessly.
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 container's startup command waits for
/tmp/testcontainers_start.shto appear, thenexecs it.containerIsStartingwrites the script viacopyFileToContainer, which is a single Container Archive PUT. On busy hosts the directory entry can become visible before the docker engine has closed the writer, and the immediateexecthen fails with ETXTBSY (exit code 126), which is what #11682 reports.This PR switches to a two-file handshake: write the starter script first, then a separate
/tmp/testcontainers_start.readymarker. The wait loop inKafkaHelper.COMMANDnow polls the marker instead of the script. The marker copy only completes after the script copy has fully closed, so by the time the wait loop unblocks the subsequentexecagainst the script is safe. The marker itself is never executed, so its own copy can race with the directory listing harmlessly.Fixes #11682.