Repository: moby/moby
File: daemon/libnetwork/sandbox.go (Go)

Code before:
		}
	}()
	for _, ep := range sb.Endpoints() {
		if !ep.isServiceEnabled() {
			if err := ep.addServiceInfoToCluster(sb); err != nil {
				return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err)
			}
			ep.enableService()
		}
	}
	log.G(context.TODO()).WithField("container", sb.containerID).Debug("EnableService DONE")
	return nil
}

// DisableService removes a managed container's endpoints from the load balancer
// and service discovery.
func (sb *Sandbox) DisableService() error {
	log.G(context.TODO()).WithField("container", sb.containerID).Debug("DisableService START")
	var failedEps []string
	for _, ep := range sb.Endpoints() {
		if !ep.isServiceEnabled() {
			continue
		}
		if err := ep.deleteServiceInfoFromCluster(sb, false, "DisableService"); err != nil {
			failedEps = append(failedEps, ep.Name())
			log.G(context.TODO()).Warnf("failed update state for endpoint %s into cluster: %v", ep.Name(), err)
		}
		ep.disableService()
	}
	log.G(context.TODO()).WithField("container", sb.containerID).Debug("DisableService DONE")
	if len(failedEps) > 0 {
		return fmt.Errorf("failed to disable service on sandbox:%s, for endpoints %s", sb.ID(), strings.Join(failedEps, ","))
	}
	return nil
}

func (sb *Sandbox) clearNetworkResources(origEp *Endpoint) error {
	ep := sb.GetEndpoint(origEp.id)
	if ep == nil {
		return fmt.Errorf("could not find the sandbox endpoint data for endpoint %s",
			origEp.id)
	}

	sb.mu.Lock()
	osSbox := sb.osSbox
	inDelete := sb.inDelete
	sb.mu.Unlock()
	if osSbox != nil {
		releaseOSSboxResources(osSbox, ep)
	}


Review comment (bug):
```suggestion
			log.G(context.TODO()).WithFields(log.Fields{
				"error: err,
				"ep": ep.Name(),
			}).Warnf("failed update state for endpoint into cluster")
```

Code after:
			}
		}
	}()
	for _, ep := range sb.Endpoints() {
		if !ep.isServiceEnabled() {
			if err := ep.addServiceInfoToCluster(sb); err != nil {
				return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err)
			}
			ep.enableService()
		}
	}
	log.G(context.TODO()).WithField("container", sb.containerID).Debug("EnableService DONE")
	return nil
}

// DisableService removes a managed container's endpoints from the load balancer
// and service discovery.
func (sb *Sandbox) DisableService() error {
	log.G(context.TODO()).WithField("container", sb.containerID).Debug("DisableService START")
	var failedEps []string
	for _, ep := range sb.Endpoints() {
		if !ep.isServiceEnabled() {
			continue
		}
		if err := ep.deleteServiceInfoFromCluster(sb, false, "DisableService"); err != nil {
			failedEps = append(failedEps, ep.Name())
			log.G(context.TODO()).WithFields(log.Fields{
				"container": sb.containerID,
				"error":     err,
				"ep":        ep.Name(),
			}).Warn("failed to update state for endpoint into cluster")
		}
		ep.disableService()
	}
	log.G(context.TODO()).WithField("container", sb.containerID).Debug("DisableService DONE")
	if len(failedEps) > 0 {
		return fmt.Errorf("failed to disable service on sandbox:%s, for endpoints %s", sb.ID(), strings.Join(failedEps, ","))
	}
	return nil
}

func (sb *Sandbox) clearNetworkResources(origEp *Endpoint) error {
	ep := sb.GetEndpoint(origEp.id)
	if ep == nil {
		return fmt.Errorf("could not find the sandbox endpoint data for endpoint %s",
			origEp.id)
	}

	sb.mu.Lock()
	osSbox := sb.osSbox
	inDelete := sb.inDelete