Race condition when starting container causes IndexOutOfBoundsException when binding ports
See original GitHub issueDescription
An intermittent issue can be seen when starting containers. It seems to be a race condition that is exacerbated when running maven with debug logging -X
. Without the debug logging containers fail to start with
[ERROR] DOCKER> Error occurred during container startup, shutting down...
The full stack trace of the exception is:
Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at jdk.internal.util.Preconditions.outOfBounds (Preconditions.java:64)
at jdk.internal.util.Preconditions.outOfBoundsCheckIndex (Preconditions.java:70)
at jdk.internal.util.Preconditions.checkIndex (Preconditions.java:248)
at java.util.Objects.checkIndex (Objects.java:372)
at java.util.ArrayList.get (ArrayList.java:459)
at com.google.gson.JsonArray.get (JsonArray.java:194)
at io.fabric8.maven.docker.model.ContainerDetails.createPortBindings (ContainerDetails.java:200)
at io.fabric8.maven.docker.model.ContainerDetails.getPortBindings (ContainerDetails.java:139)
at io.fabric8.maven.docker.service.RunService.updateMappedPortsAndAddresses (RunService.java:461)
at io.fabric8.maven.docker.service.RunService.createAndStartContainer (RunService.java:156)
at io.fabric8.maven.docker.service.helper.StartContainerExecutor.startContainer (StartContainerExecutor.java:47)
at io.fabric8.maven.docker.StartMojo.lambda$startImage$0 (StartMojo.java:299)
When adding some logging to the maven plugin I can see that during the the io.fabric8.maven.docker.model.ContainerDetails.createPortBindings
method call the ports will usually have some mappings like this:
Ports:{"5432/tcp":[{"HostIp":"0.0.0.0","HostPort":"54290"}],}
However sometimes the array of mapped ports will be empty, e.g.
Ports:{"5432/tcp":[]}
This causes the exception as the array is expected to not be empty and the first element retrieved.
I believe the call to the api in io.fabric8.maven.docker.service.RunService.updateMappedPortsAndAddresses
is sometimes returning this empty data for the port if called too early.
The solution I would propose would be to retry the API call and the createPortBindings
activity if an empty array is encountered.
Info
- docker-maven-plugin version : 0.34.1
- Maven version (
mvn -v
) :
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 11.0.10, vendor: AdoptOpenJDK, runtime: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
- Docker version : 3.2.2
- If it’s a bug, how to reproduce : The issue is intermittent so impossible to consistently reproduce. It appeared to be more easily reproducible when running
mvn verify
with-X
flag.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Good Morning 😃 now i did the test right, and now it works. 😃 thanks for fixing the plugin. cheers g
So im not seeing that log message and the line indicated by the stack trace
io.fabric8.maven.docker.model.ContainerDetails.createPortBindings (ContainerDetails.java:200)
is (in my code)which cant be throwing that exception. So it really looks like the updated code is not being used.