Make inspect-rewrite wait if the start operation is still in progress

This commit is contained in:
Bryan Boreham committed 2015-10-30 13:34:16 +00:00
1 parent a6336149f8
commit 5eaff802d4
3 files changed
+21 -3

No files matched your search

+3 -2
View File
@@ -22,19 +22,20 @@ func (i *inspectContainerInterceptor) InterceptResponse(r *http.Response) error
return err
}
if err := updateContainerNetworkSettings(container); err != nil {
if err := updateContainerNetworkSettings(container, i.proxy); err != nil {
Log.Warningf("Inspecting container %s failed: %s", container["Id"], err)
}
return marshalResponseBody(r, container)
}
func updateContainerNetworkSettings(container jsonObject) error {
func updateContainerNetworkSettings(container jsonObject, proxy *Proxy) error {
containerID, err := container.String("Id")
if err != nil {
return err
}
proxy.waitForStartByIdent(containerID)
mac, ips, nets, err := weaveContainerIPs(containerID)
if err != nil || len(ips) == 0 {
return err
+1 -1
View File
@@ -27,7 +27,7 @@ func (i *inspectExecInterceptor) InterceptResponse(r *http.Response) error {
return err
}
if err := updateContainerNetworkSettings(container); err != nil {
if err := updateContainerNetworkSettings(container, i.proxy); err != nil {
Log.Warningf("Inspecting exec %s failed: %s", exec["Id"], err)
}
+17
View File
@@ -358,6 +358,23 @@ func (proxy *Proxy) waitForStart(r *http.Request) error {
return nil
}
// If some other operation is waiting for a container to start, join in the wait
func (proxy *Proxy) waitForStartByIdent(ident string) {
var ch chan struct{}
proxy.Lock()
for _, wait := range proxy.waiters {
if ident == wait.ident {
ch = wait.ch
break
}
}
proxy.Unlock()
if ch != nil {
Log.Debugf("Wait for start of container %s", ident)
<-ch
}
}
func (proxy *Proxy) ContainerDied(ident string) {
}