2015-04-13 09:36:04 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-07-23 14:34:40 +03:00
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2015-04-13 20:30:07 +03:00
|
|
|
"net/http"
|
2015-04-13 09:36:04 +03:00
|
|
|
"strings"
|
2015-08-04 14:44:54 +03:00
|
|
|
"sync"
|
2015-04-18 19:46:47 +03:00
|
|
|
|
2015-10-15 17:28:21 +03:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-18 19:46:47 +03:00
|
|
|
"github.com/go-check/check"
|
2015-04-13 09:36:04 +03:00
|
|
|
)
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 09:35:36 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
2015-04-13 09:36:04 +03:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
|
2015-04-13 20:30:07 +03:00
|
|
|
status, _, err := sockRequest("POST", endpoint, nil)
|
2015-10-15 17:28:21 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
2015-04-13 09:36:04 +03:00
|
|
|
}
|
2015-07-23 14:34:40 +03:00
|
|
|
|
|
|
|
// Part of #14845
|
|
|
|
func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) {
|
|
|
|
name := "exec_resize_test"
|
|
|
|
dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
|
|
|
|
|
2015-08-04 14:44:54 +03:00
|
|
|
testExecResize := func() error {
|
|
|
|
data := map[string]interface{}{
|
|
|
|
"AttachStdin": true,
|
|
|
|
"Cmd": []string{"/bin/sh"},
|
|
|
|
}
|
|
|
|
uri := fmt.Sprintf("/containers/%s/exec", name)
|
|
|
|
status, body, err := sockRequest("POST", uri, data)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if status != http.StatusCreated {
|
|
|
|
return fmt.Errorf("POST %s is expected to return %d, got %d", uri, http.StatusCreated, status)
|
|
|
|
}
|
2015-07-23 14:34:40 +03:00
|
|
|
|
2015-08-04 14:44:54 +03:00
|
|
|
out := map[string]string{}
|
|
|
|
err = json.Unmarshal(body, &out)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("ExecCreate returned invalid json. Error: %q", err.Error())
|
|
|
|
}
|
2015-07-23 14:34:40 +03:00
|
|
|
|
2015-08-04 14:44:54 +03:00
|
|
|
execID := out["Id"]
|
|
|
|
if len(execID) < 1 {
|
|
|
|
return fmt.Errorf("ExecCreate got invalid execID")
|
|
|
|
}
|
2015-07-23 14:34:40 +03:00
|
|
|
|
2015-08-04 14:44:54 +03:00
|
|
|
payload := bytes.NewBufferString(`{"Tty":true}`)
|
|
|
|
conn, _, err := sockRequestHijack("POST", fmt.Sprintf("/exec/%s/start", execID), payload, "application/json")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to start the exec: %q", err.Error())
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
2015-07-23 14:34:40 +03:00
|
|
|
|
2015-08-04 14:44:54 +03:00
|
|
|
_, rc, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), nil, "text/plain")
|
|
|
|
// It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned.
|
|
|
|
if err == io.ErrUnexpectedEOF {
|
|
|
|
return fmt.Errorf("The daemon might have crashed.")
|
|
|
|
}
|
2015-07-23 14:34:40 +03:00
|
|
|
|
2015-08-04 14:44:54 +03:00
|
|
|
if err == nil {
|
|
|
|
rc.Close()
|
|
|
|
}
|
2015-07-23 14:34:40 +03:00
|
|
|
|
2015-08-04 14:44:54 +03:00
|
|
|
// We only interested in the io.ErrUnexpectedEOF error, so we return nil otherwise.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// The panic happens when daemon.ContainerExecStart is called but the
|
|
|
|
// container.Exec is not called.
|
|
|
|
// Because the panic is not 100% reproducible, we send the requests concurrently
|
|
|
|
// to increase the probability that the problem is triggered.
|
|
|
|
var (
|
|
|
|
n = 10
|
|
|
|
ch = make(chan error, n)
|
|
|
|
wg sync.WaitGroup
|
|
|
|
)
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
if err := testExecResize(); err != nil {
|
|
|
|
ch <- err
|
2015-07-23 14:34:40 +03:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2015-08-04 14:44:54 +03:00
|
|
|
wg.Wait()
|
|
|
|
select {
|
|
|
|
case err := <-ch:
|
|
|
|
c.Fatal(err.Error())
|
|
|
|
default:
|
2015-07-23 14:34:40 +03:00
|
|
|
}
|
|
|
|
}
|