Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Commit

Permalink
Fix #65.
Browse files Browse the repository at this point in the history
The Docker daemon seems to have a race condition where it can report a
'bad file descriptor' error when trying to resize a container that has
just stopped.
  • Loading branch information
charleskorn committed Feb 14, 2019
1 parent d257ef3 commit f9a3084
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/src/main/kotlin/batect/docker/DockerAPI.kt
Expand Up @@ -460,6 +460,10 @@ class DockerAPI(
throw ContainerStoppedException(message)
}

if (error.statusCode == 500 && error.message.trim() == "bad file descriptor: unknown") {
throw ContainerStoppedException("$message (the container may have stopped quickly after starting)")
}

throw DockerException(message)
}
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/test/kotlin/batect/docker/DockerAPISpec.kt
Expand Up @@ -574,6 +574,14 @@ object DockerAPISpec : Spek({
}
}

on("the container being stopped and the daemon returning a 'bad file descriptor' error") {
httpClient.mockPost(expectedUrl, """{"message": "bad file descriptor: unknown"}""", 500)

it("throws an appropriate exception") {
assertThat({ api.resizeContainerTTY(container, dimensions) }, throws<ContainerStoppedException>(withMessage("Resizing TTY for container 'the-container-id' failed: bad file descriptor: unknown (the container may have stopped quickly after starting)")))
}
}

on("the API call failing") {
httpClient.mockPost(expectedUrl, """{"message": "Something went wrong."}""", 418)

Expand Down

0 comments on commit f9a3084

Please sign in to comment.