2015-04-13 06:36:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-07-23 11:34:40 +00:00
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2015-04-13 17:30:07 +00:00
|
|
|
"net/http"
|
2015-04-13 06:36:04 +00:00
|
|
|
"strings"
|
2015-08-04 11:44:54 +00:00
|
|
|
"sync"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2015-10-15 14:28:21 +00:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2015-04-13 06:36:04 +00:00
|
|
|
)
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 06:35:36 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
2015-04-13 06:36:04 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
|
2015-04-13 17:30:07 +00:00
|
|
|
status, _, err := sockRequest("POST", endpoint, nil)
|
2015-10-15 14:28:21 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
2015-04-13 06:36:04 +00:00
|
|
|
}
|
2015-07-23 11:34:40 +00:00
|
|
|
|
|
|
|
// Part of #14845
|
|
|
|
func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-27 23:17:55 +00:00
|
|
|
|
2015-07-23 11:34:40 +00:00
|
|
|
name := "exec_resize_test"
|
|
|
|
dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
|
|
|
|
|
2015-08-04 11:44:54 +00: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 11:34:40 +00:00
|
|
|
|
2015-08-04 11:44:54 +00: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 11:34:40 +00:00
|
|
|
|
2015-08-04 11:44:54 +00:00
|
|
|
execID := out["Id"]
|
|
|
|
if len(execID) < 1 {
|
|
|
|
return fmt.Errorf("ExecCreate got invalid execID")
|
|
|
|
}
|
2015-07-23 11:34:40 +00:00
|
|
|
|
2015-08-04 11:44:54 +00: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 11:34:40 +00:00
|
|
|
|
2015-08-04 11:44:54 +00: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 11:34:40 +00:00
|
|
|
|
2015-08-04 11:44:54 +00:00
|
|
|
if err == nil {
|
|
|
|
rc.Close()
|
|
|
|
}
|
2015-07-23 11:34:40 +00:00
|
|
|
|
2015-08-04 11:44:54 +00: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 11:34:40 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2015-08-04 11:44:54 +00:00
|
|
|
wg.Wait()
|
|
|
|
select {
|
|
|
|
case err := <-ch:
|
|
|
|
c.Fatal(err.Error())
|
|
|
|
default:
|
2015-07-23 11:34:40 +00:00
|
|
|
}
|
|
|
|
}
|