Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InternalCommandPortListeningCheck always fails for containers built without /bin/sh #3317

Open
rnorth opened this issue Oct 11, 2020 · 5 comments

Comments

@rnorth
Copy link
Member

rnorth commented Oct 11, 2020

Relates to #2984

I'm surprised we've not come across this earlier, but the default TCP port listening detector InternalCommandPortListeningCheck does not work for containers that do not have /bin/sh included.

This predominantly affects images built upon scratch.

The workaround/solution is to use a more application specific WaitStrategy - e.g. an HTTP wait strategy.

However the log messages don't make this easy to realise.

Given that we do both the internal and external port checks for a good reason, I don't think we can just rely on the external port check. Still perhaps we can raise a very specific error message if /bin/sh is not available inside the container.

lanwen added a commit to lanwen/testcontainers-java that referenced this issue Nov 7, 2020
fixes testcontainers#2984, testcontainers#2710

in mock-server/mockserver@9f27af0 mockserver introduced a GET http healthcheck (what was released in 5.9.0) and since 5.11.0 uses distroless image, with the default wait strategy, we hit into testcontainers#3317

As the 5.11.0+ is actually a smaller image, more secure and 5.9.0 was released almost a year ago (which means users with 5.9.0+ versions would be able to update testcontainers without changes), I think worth bumping the base version.

For the users on old versions the old behaviour could be set with the default waiting strategy back
`.waitingFor(Wait.defaultWaitStrategy())`.

This PR also brings two small changes to be complete - mockserver official image now is `mockserver/mockserver` (but I added previous as a compatible).
And added small note to the docs regarding matched version of a client, as anyway had to change docs after test adjustments (wasn't able to test properly with rule in the same class as old version).
@vcvitaly
Copy link
Contributor

I can take it.

@vcvitaly
Copy link
Contributor

vcvitaly commented Feb 22, 2021

@rnorth
I noticed that Testcontainers heavily uses static classes, for example:

try {
            ExecResult result = ExecInContainerPattern.execInContainer(waitStrategyTarget

or

default Container.ExecResult execInContainer(Charset outputCharset, String... command) throws UnsupportedOperationException, IOException, InterruptedException {
        return ExecInContainerPattern.execInContainer(getContainerInfo(), outputCharset, command);
    }

which makes it hard to unit test/mock some things. Is it done on purpose or have there been any ideas to change that?

Asking that because fixing this issue would require to run an integration test which is heavier and I read in some issue that it's not desirable to increase build running time with heavy tests.

@bsideup
Copy link
Member

bsideup commented Feb 22, 2021

@vcvitaly overall, we prefer integration tests over unit tests. We do recommend avoiding unnecessary load on our CI but we don't mind it if it is needed.

Also, Testcontainers' nature is context-less, to make it easier to use in tests, hence the heavy usage of static objects.

@vcvitaly
Copy link
Contributor

vcvitaly commented Feb 25, 2021

If an error is thrown, HostPortWaitStrategy will be running Unreliables.retryUntilTrue until the timeout is reached.
I think in such cases as this it should be aborted immediately on some specific exception, however at the moment it's not possible with Unreliables.

I described the issue in rnorth/duct-tape#11

@bedla
Copy link
Contributor

bedla commented Apr 29, 2023

Hi, I have create this PR #6942 pls take a look and say what do you think? Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants