浏览代码

Verify Endpoint.Info() before accessing it

- During concurrent operations in multihost environment,
  it is possible that the implementer of `EndpointInfo`
  is nil. It simply means the endpoint is no longer
  available in the datastore.

Signed-off-by: Alessandro Boch <aboch@docker.com>
Alessandro Boch 9 年之前
父节点
当前提交
54d22cbd9a
共有 2 个文件被更改,包括 16 次插入3 次删除
  1. 11 2
      api/server/router/network/network_routes.go
  2. 5 1
      daemon/container_unix.go

+ 11 - 2
api/server/router/network/network_routes.go

@@ -191,7 +191,11 @@ func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource {
 
 
 	epl := nw.Endpoints()
 	epl := nw.Endpoints()
 	for _, e := range epl {
 	for _, e := range epl {
-		sb := e.Info().Sandbox()
+		ei := e.Info()
+		if ei == nil {
+			continue
+		}
+		sb := ei.Sandbox()
 		if sb == nil {
 		if sb == nil {
 			continue
 			continue
 		}
 		}
@@ -233,7 +237,12 @@ func buildEndpointResource(e libnetwork.Endpoint) types.EndpointResource {
 	}
 	}
 
 
 	er.EndpointID = e.ID()
 	er.EndpointID = e.ID()
-	if iface := e.Info().Iface(); iface != nil {
+	ei := e.Info()
+	if ei == nil {
+		return er
+	}
+
+	if iface := ei.Iface(); iface != nil {
 		if mac := iface.MacAddress(); mac != nil {
 		if mac := iface.MacAddress(); mac != nil {
 			er.MacAddress = mac.String()
 			er.MacAddress = mac.String()
 		}
 		}

+ 5 - 1
daemon/container_unix.go

@@ -1191,7 +1191,11 @@ func (container *Container) disconnectFromNetwork(n libnetwork.Network) error {
 	)
 	)
 
 
 	s := func(current libnetwork.Endpoint) bool {
 	s := func(current libnetwork.Endpoint) bool {
-		if sb := current.Info().Sandbox(); sb != nil {
+		epInfo := current.Info()
+		if epInfo == nil {
+			return false
+		}
+		if sb := epInfo.Sandbox(); sb != nil {
 			if sb.ContainerID() == container.ID {
 			if sb.ContainerID() == container.ID {
 				ep = current
 				ep = current
 				sbox = sb
 				sbox = sb