Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

inspectContainer fails because of large ExitCode #1052

Closed
DavidHaunsch opened this issue Aug 14, 2018 · 3 comments
Closed

inspectContainer fails because of large ExitCode #1052

DavidHaunsch opened this issue Aug 14, 2018 · 3 comments

Comments

@DavidHaunsch
Copy link
Contributor

Description

Lately I started a micrsoft/iis nanoserver. After stopping the container I wanted to get the state (including the exit code). But this request failed because the exit code is out of range of int.

How to reproduce

import org.junit.Test;

import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.messages.ContainerConfig;
import com.spotify.docker.client.messages.ContainerCreation;
import com.spotify.docker.client.messages.ContainerState;

public class MyTest {
    @Test
    public void test() throws Exception {
        DockerClient dockerClient = new DefaultDockerClient("http://localhost:2375");
        DockerImage dockerImage = DockerImage.builder("microsoft/iis").tag("nanoserver-10.0.14393.1944").build();
        dockerClient.pull(dockerImage.toString());
        ContainerConfig containerConfig = ContainerConfig.builder().image(dockerImage.toString()).build();
        ContainerCreation containerCreation = dockerClient.createContainer(containerConfig);
        dockerClient.startContainer(containerCreation.id());
        dockerClient.stopContainer(containerCreation.id(), 5);
        ContainerState state = dockerClient.inspectContainer(containerCreation.id()).state(); // <- fails here
        // do anything with state
    }
}

What do you expect

I expect to receive the ContainerState including a large ExitCode. To fix this, the ExitCode should be Long for instance instead of Integer.

What happened instead

dockerClient.inspectContainer(containerCreation.id()).state() failed with following exception:

com.spotify.docker.client.exceptions.DockerRequestException: Request error: GET http://localhost:2375/containers/8ca5d061296e7cd47b72fb9d4a2275cb40471688a6698e9d5e8e373bc0e2715a/json: 200

	at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:2717)
	at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:2656)
	at com.spotify.docker.client.DefaultDockerClient.inspectContainer(DefaultDockerClient.java:1018)
	at mypackage.MyTest.test(MyTest.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: com.spotify.docker.client.shaded.javax.ws.rs.client.ResponseProcessingException: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Numeric value (2147942405) out of range of int
 at [Source: (com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 301]
 at [Source: (com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 291] (through reference chain: com.spotify.docker.client.messages.ContainerInfo["State"]->com.spotify.docker.client.messages.ContainerState["ExitCode"])
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:806)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.JerseyInvocation$5.completed(JerseyInvocation.java:773)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.ClientRuntime.processResponse(ClientRuntime.java:198)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.ClientRuntime.access$300(ClientRuntime.java:79)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.ClientRuntime$2.run(ClientRuntime.java:180)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.internal.Errors.process(Errors.java:315)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.internal.Errors.process(Errors.java:297)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.internal.Errors.process(Errors.java:267)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:340)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.ClientRuntime$3.run(ClientRuntime.java:210)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Caused by: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Numeric value (2147942405) out of range of int
 at [Source: (com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 301]
 at [Source: (com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 291] (through reference chain: com.spotify.docker.client.messages.ContainerInfo["State"]->com.spotify.docker.client.messages.ContainerState["ExitCode"])
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:391)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:351)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1704)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:530)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:417)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1280)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:529)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:528)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:417)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1280)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:1574)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:965)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.jaxrs.base.ProviderBase.readFrom(ProviderBase.java:815)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:256)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:235)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:808)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
	at com.spotify.docker.client.shaded.org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:803)
	... 17 more
Caused by: com.spotify.docker.client.shaded.com.fasterxml.jackson.core.JsonParseException: Numeric value (2147942405) out of range of int
 at [Source: (com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 301]
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:663)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.core.base.ParserBase.convertNumberToInt(ParserBase.java:869)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.core.base.ParserBase._parseIntValue(ParserBase.java:801)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.core.base.ParserBase.getIntValue(ParserBase.java:645)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:472)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:452)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:529)
	at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:528)
	... 38 more

Software:

  • docker version: 18.06.0-ce
  • docker API version: 1.38
  • Spotify's docker-client version: 8:11:4:shaded
@johnflavin
Copy link
Contributor

I was surprised by this exit code value, since I'm used to shell values which are between 0 and 255 (if I remember correctly). So I investigated this. Turns out it is possible and is definitely a bug.

First, I'll snip out the relevant potion of the stacktrace from the OP

Caused by: c.s.d.c.shaded.com.fasterxml.jackson.databind.JsonMappingException: Numeric value (2147942405) out of range of int
 at [Source: (c.s.d.c.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 301]
 at [Source: (c.s.d.c.shaded.org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 291] (through reference chain: c.s.d.c.messages.ContainerInfo["State"]->c.s.d.c.messages.ContainerState["ExitCode"])

So we know the error was caused by an ExitCode value of 2147942405.

Is that value even possible? Let's look at the types involved.

  • In swagger.yaml, the type of Container.State.ExitCode is "integer". Ok... what does that mean?
  • In the docker API types, ContainerState.ExitCode is a go int. Ok... what does that mean?
  • From this SO answer it appears the go int type can be 8, 16, 32, or 64 bits depending on the system.

Since the max int32 is 2147483647, which is less than the value received here of 2147942405, we can infer that on this system docker is using int64. Which makes sense, as most modern computers on which one would run docker use 64-bit processors.

According to the Java language spec, int, which underlies Integer, is 32 bits, whereas long and Long are 64 bits. So, to capture the full range of possible values, everywhere docker uses integer in swagger.yaml, we should bind that to a Long.

@mattnworb
Copy link
Member

@DavidHaunsch what OS are you running Docker on, and what OS runs inside your container?

@DavidHaunsch
Copy link
Contributor Author

DavidHaunsch commented Aug 14, 2018

@johnflavin @mattnworb Thanks for your answer!
@mattnworb In this case on windows with windows containers (required by microsoft/iis image), but that doesn't matter since the ExitCode is an Integer on any OS. I just stumbled over that using exactly this image.

davidxia added a commit that referenced this issue Aug 20, 2018
updated CHANGELOG and bumped minor version.

see #1052
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants