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

docker: log that a container has been killed by the OOM killer #3459

Merged
merged 2 commits into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,13 @@ func (h *DockerHandle) run() {
werr = fmt.Errorf("Docker container exited with non-zero exit code: %d", exitCode)
}

container, ierr := h.waitClient.InspectContainer(h.containerID)
if ierr != nil {
h.logger.Printf("[ERR] driver.docker: failed to inspect container %s: %v", h.containerID, ierr)
} else if container.State.OOMKilled {
werr = fmt.Errorf("Docker container killed by OOM killer")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the message just to be OOM Killed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

close(h.doneCh)

// Shutdown the syslog collector
Expand Down
50 changes: 50 additions & 0 deletions client/driver/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1753,3 +1753,53 @@ func TestDockerDriver_AuthConfiguration(t *testing.T) {
}
}
}

func TestDockerDriver_OOMKilled(t *testing.T) {
if !tu.IsTravis() {
t.Parallel()
}
if !testutil.DockerIsConnected(t) {
t.Skip("Docker not connected")
}

task := &structs.Task{
Name: "oom-killed",
Driver: "docker",
Config: map[string]interface{}{
"image": "busybox",
"load": "busybox.tar",
"command": "sh",
// Incrementally creates a bigger and bigger variable.
"args": []string{"-c", "x=a; while true; do eval x='$x$x'; done"},
},
LogConfig: &structs.LogConfig{
MaxFiles: 10,
MaxFileSizeMB: 10,
},
Resources: &structs.Resources{
CPU: 250,
MemoryMB: 10,
DiskMB: 20,
Networks: []*structs.NetworkResource{},
},
}

_, handle, cleanup := dockerSetup(t, task)
defer cleanup()

select {
case res := <-handle.WaitCh():
if res.Successful() {
t.Fatalf("expected error, but container exited successfull")
}

if !strings.Contains(res.Err.Error(), "killed by OOM killer") {
t.Fatalf("not killed by OOM killer: %s", res.Err)
}

t.Logf("Successfully killed by OOM killer")

case <-time.After(time.Duration(tu.TestMultiplier()*5) * time.Second):
t.Fatalf("timeout")
}
}