Fix SEGFAULT if dns resolv error

Per registry.doRequest, res and client might be nil in case of error
For example, dns resolution errors, /etc/docker/certs.d perms, failed
loading of x509 cert ...
This will make res.StatusCode and res.Body SEGFAULT.

fixes #7860 
Sorry I forgot to reply yesterday:
You can prevent copy pasting setTimeout and just do this:
```
c := make(chan struct{})
go func() {
   r := spawnTestRegistrySession(t)
   //[...]   
   close(c)
}()
select {
case <-c:
case <-time.After(time.Second):
    t.Fatal("Lookup failed should not segfault")
}
```