agent/eni/networkutils/utils_linux.go
func (retriever *macAddressRetriever) retrieve() (string, error) {
	backoff := retry.NewExponentialBackoff(macAddressBackoffMin, macAddressBackoffMax,
		macAddressBackoffJitter, macAddressBackoffMultiple)
	ctx, cancel := context.WithTimeout(retriever.ctx, retriever.timeout)
	defer cancel()

	err := retry.RetryWithBackoffCtx(ctx, backoff, func() error {
		retErr := retriever.retrieveOnce()
		if retErr != nil {
			seelog.Warnf("Unable to retrieve mac address for device '%s': %v",
				retriever.dev, retErr)
			return retErr
		}

		if retriever.macAddress == "" {
			seelog.Debugf("Empty mac address for device '%s'", retriever.dev)
			// Return a retriable error when mac address is empty. If the error
			// is not wrapped with the RetriableError interface, RetryWithBackoffCtx
			// treats them as retriable by default
			return errors.Errorf("eni mac address: retrieved empty address for device %s",
				retriever.dev)
		}

		return nil
	})
	if err != nil {
		return "", err
	}
	// RetryWithBackoffCtx returns nil when the context is cancelled. Check if there was
	// a timeout here. TODO: Fix RetryWithBackoffCtx to return ctx.Err() on context Done()
	if err = ctx.Err(); err != nil {
		return "", errors.Wrapf(err, "eni mac address: timed out waiting for eni device '%s'",
			retriever.dev)
	}

	return retriever.macAddress, nil
}
func (retriever *macAddressRetriever) retrieve() (string, error) {
	backoff := retry.NewExponentialBackoff(macAddressBackoffMin, macAddressBackoffMax,
		macAddressBackoffJitter, macAddressBackoffMultiple)
	ctx, cancel := context.WithTimeout(retriever.ctx, retriever.timeout)
	defer cancel()

	err := retry.RetryWithBackoffCtx(ctx, backoff, func() error {
		retErr := retriever.retrieveOnce()
		if retErr != nil {
			seelog.Warnf("Unable to retrieve mac address for device '%s': %v",
				retriever.dev, retErr)
			return retErr
		}

		if retriever.macAddress == "" {
			seelog.Debugf("Empty mac address for device '%s'", retriever.dev)
			// Return a retriable error when mac address is empty. If the error
			// is not wrapped with the RetriableError interface, RetryWithBackoffCtx
			// treats them as retriable by default
			return errors.Errorf("eni mac address: retrieved empty address for device %s",
				retriever.dev)
		}

		return nil
	})
	if err != nil {
		return "", err
	}
	// RetryWithBackoffCtx returns nil when the context is cancelled. Check if there was
	// a timeout here. TODO: Fix RetryWithBackoffCtx to return ctx.Err() on context Done()
	if err = ctx.Err(); err != nil {
		return "", errors.Wrapf(err, "eni mac address: timed out waiting for eni device '%s'",
			retriever.dev)
	}

	return retriever.macAddress, nil
}
func ( retriever * macAddressRetriever ) retrieve ( ) ( string , error ) { backoff := retry . NewExponentialBackoff ( macAddressBackoffMin , macAddressBackoffMax , macAddressBackoffJitter , macAddressBackoffMultiple ) ctx , cancel := context . WithTimeout ( retriever . ctx , retriever . timeout ) defer cancel ( ) err := retry . RetryWithBackoffCtx ( ctx , backoff , func ( ) error { retErr := retriever . retrieveOnce ( ) if retErr != nil { seelog . Warnf ( " " , retriever . dev , retErr ) return retErr } if retriever . macAddress == " " { seelog . Debugf ( " " , retriever . dev ) // Return a retriable error when mac address is empty. If the error // is not wrapped with the RetriableError interface, RetryWithBackoffCtx // treats them as retriable by default return errors . Errorf ( " " , retriever . dev ) } return nil } ) if err != nil { return " " , err } // RetryWithBackoffCtx returns nil when the context is cancelled. Check if there was // a timeout here. TODO: Fix RetryWithBackoffCtx to return ctx.Err() on context Done() if err = ctx . Err ( ) ; err != nil { return " " , errors . Wrapf ( err , " " , retriever . dev ) } return retriever . macAddress , nil }
// retrieve retrives the mac address of a network device. If the retrieved mac
// address is empty, it retries the operation with a timeout specified by the
// caller
retrieve retrives the mac address of a network device . If the retrieved mac address is empty it retries the operation with a timeout specified by the caller