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

no timeout on client.PullImage #802

Open
HeikoOnnebrink opened this issue Sep 18, 2019 · 3 comments
Open

no timeout on client.PullImage #802

HeikoOnnebrink opened this issue Sep 18, 2019 · 3 comments
Labels

Comments

@HeikoOnnebrink
Copy link

Situation:
I have a docker daemon running under CoreOS and exposed the TCP port by creating and binding a TCP socket (as described in the docs https://coreos.com/os/docs/latest/customizing-docker.html)

I have the situation that in some cases the server config (using Ignition) fails and the docker daemon does not start up, but the socket on port 2375 is reachable.
When calling now client.PullImage the request stays hanging at that point.
I tried to pass InactivityTimeout but without result.
Is there some other way to pass some timeout to the PullImage call?
thx & cheers
Heiko

@fsouza fsouza added the bug label Sep 18, 2019
@fsouza
Copy link
Owner

fsouza commented Sep 18, 2019

Oh interesting, this sounds like a bug. Thanks for reporting! I'm able to reproduce it with nc:

$ nc -l 2375 &>nc.out &
$ cat pull.go
package main

import (
        "bytes"
        "log"

        docker "github.com/fsouza/go-dockerclient"
)

func main() {
        client, err := docker.NewClient("tcp://localhost:2375")
        if err != nil {
                log.Fatal(err)
        }

        var buf bytes.Buffer
        err = client.PullImage(docker.PullImageOptions{
                Repository:        "openjdk",
                OutputStream:      &buf,
                InactivityTimeout: 300e6,
        }, docker.AuthConfiguration{})
        if err != nil {
                log.Fatal(err)
        }

        log.Print(&buf)
}
$ go run pull.go
[hangs]

I'll investigate why the InactivityTimeout isn't working.

@fsouza
Copy link
Owner

fsouza commented Sep 18, 2019

So the issue is that the client doesn't get to the code that handles the InactivityTimeout because it applies only to reads of the body and in this case the server accepts the connection, takes the request but doesn't respond. This will take a little longer to fix, but you could use a context to workaround this issue, making a call that should return quickly using a short timeout (for example, VersionWithContext()).

@HeikoOnnebrink
Copy link
Author

great to hear that you could reproduce it instantly. As you plan to fix it I will not touch the docker remote API code and wait for your fix here.
In between I just drop in a small API test call before interacting with the API from the docker client:

netClient := &http.Client{Timeout: time.Second * 5}
if _,err := netClient.Get("http://ip:2375/version"); err != nil{
<do the fail code>
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants