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

testing: fix data race when reading container state in some handlers #701

Merged
merged 1 commit into from
Dec 12, 2017
Merged
Changes from all commits
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
6 changes: 6 additions & 0 deletions testing/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ func (s *DockerServer) topContainer(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
s.cMut.RLock()
defer s.cMut.RUnlock()
if !container.State.Running {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Container %s is not running", id)
Expand Down Expand Up @@ -787,11 +789,13 @@ func (s *DockerServer) attachContainer(w http.ResponseWriter, r *http.Request) {
}()
}
outStream := stdcopy.NewStdWriter(conn, stdcopy.Stdout)
s.cMut.RLock()
if container.State.Running {
fmt.Fprintf(outStream, "Container is running\n")
} else {
fmt.Fprintf(outStream, "Container is not running\n")
}
s.cMut.RUnlock()
fmt.Fprintln(outStream, "What happened?")
fmt.Fprintln(outStream, "Something happened")
wg.Wait()
Expand Down Expand Up @@ -919,11 +923,13 @@ func (s *DockerServer) logContainer(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "application/vnd.docker.raw-stream")
w.WriteHeader(http.StatusOK)
s.cMut.RLock()
if container.State.Running {
fmt.Fprintf(w, "Container is running\n")
} else {
fmt.Fprintf(w, "Container is not running\n")
}
s.cMut.RUnlock()
fmt.Fprintln(w, "What happened?")
fmt.Fprintln(w, "Something happened")
if r.URL.Query().Get("follow") == "1" {
Expand Down