// RetryNextBoxAudit selects a teamID from the box audit retry queue and performs another box audit.
963654
func (a *BoxAuditor) RetryNextBoxAudit(mctx libkb.MetaContext) (attempt *keybase1.BoxAuditAttempt, err error) {
	mctx = a.initMctx(mctx)
	defer mctx.TraceTimed("RetryNextBoxAudit", func() error { return err })()

	if !ShouldRunBoxAudit(mctx) {
		mctx.Debug("Box auditor feature flagged off; not RetryNextBoxAuditing...")
		return nil, nil
	}

	queueItem, err := a.popRetryQueue(mctx)
	if err != nil {
		return nil, err
	}
	if queueItem == nil {
		mctx.Debug("Retry queue empty, succeeding vacuously")
		return nil, nil
	}
	return a.BoxAuditTeam(mctx, (*queueItem).TeamID)
}
450570
func NewAudit(info AppInfo, logger Logger, next http.Handler) *Audit {
	basePath := info.BasePath
	if basePath == "" {
		basePath = "/"
	}
	return &Audit{
		Logger:   logger,
		basePath: basePath,
		next:     next,
		info:     info,
	}
}
1017667
func (c *Client) RetryDeadJob(diedAt int64, jobID string) error {
	// Get queues for job names
	queues, err := c.Queues()
	if err != nil {
		logError("client.retry_all_dead_jobs.queues", err)
		return err
	}

	// Extract job names
	var jobNames []string
	for _, q := range queues {
		jobNames = append(jobNames, q.JobName)
	}

	script := redis.NewScript(len(jobNames)+1, redisLuaRequeueSingleDeadCmd)

	args := make([]interface{}, 0, len(jobNames)+1+3)
	args = append(args, redisKeyDead(c.namespace)) // KEY[1]
	for _, jobName := range jobNames {
		args = append(args, redisKeyJobs(c.namespace, jobName)) // KEY[2, 3, ...]
	}
	args = append(args, redisKeyJobsPrefix(c.namespace)) // ARGV[1]
	args = append(args, nowEpochSeconds())
	args = append(args, diedAt)
	args = append(args, jobID)

	conn := c.pool.Get()
	defer conn.Close()

	cnt, err := redis.Int64(script.Do(conn, args...))
	if err != nil {
		logError("client.retry_dead_job.do", err)
		return err
	}

	if cnt == 0 {
		return ErrNotRetried
	}

	return nil
}
257904
func newErrorBox(err error, code int, msgs Messages, args ...interface{}) *errorBox {
	return &errorBox{
		err:  err,
		code: code,
		msg:  msgs.Format(code, args...),
		info: retrieveCallInfo(),
	}
}
29699
func (c *Conn) lockedReceive() ([]Message, error) {
	msgs, err := c.receive()
	if err != nil {
		c.debug(func(d *debugger) {
			d.debugf(1, "recv: err: %v", err)
		})

		return nil, err
	}

	c.debug(func(d *debugger) {
		for _, m := range msgs {
			d.debugf(1, "recv: %+v", m)
		}
	})

	// When using nltest, it's possible for zero messages to be returned by receive.
	if len(msgs) == 0 {
		return msgs, nil
	}

	// Trim the final message with multi-part done indicator if
	// present.
	if m := msgs[len(msgs)-1]; m.Header.Flags&Multi != 0 && m.Header.Type == Done {
		return msgs[:len(msgs)-1], nil
	}

	return msgs, nil
}
1264667
func (m *memoryMailBox) signalUntilReset(cType courierType,
	done chan struct{}) error {

	for {
		switch cType {
		case wireCourier:
			m.wireCond.Signal()
		case pktCourier:
			m.pktCond.Signal()
		}

		select {
		case <-time.After(time.Millisecond):
			continue
		case <-done:
			return nil
		case <-m.quit:
			return ErrMailBoxShuttingDown
		}
	}
}
302599
func (it *bytesKeyValIterator) GetNext() (kv keyval.BytesKeyVal, lastReceived bool) {
	if it.err != nil {
		return nil, true
	}
	if it.index >= len(it.values) {
		if it.cursor == 0 {
			return nil, true
		}
		var err error
		it.keys, it.cursor, err = scanKeys(it.db, it.pattern, it.cursor)
		if err != nil {
			it.err = err
			it.db.Errorf("GetNext() failed: %s (pattern %s)", err.Error(), it.pattern)
			return nil, true
		}
		if len(it.keys) == 0 {
			return nil, it.cursor == 0
		}
		it.values, err = getValues(it.db, it.keys)
		if err != nil {
			it.err = err
			it.db.Errorf("GetNext() failed: %s (pattern %s)", err.Error(), it.pattern)
			return nil, true
		}
		it.index = 0
	}

	key := it.keys[it.index]
	if it.trimPrefix != nil {
		key = it.trimPrefix(key)
	}

	value := it.values[it.index]
	var prevValue []byte
	if it.index > 0 {
		prevValue = it.values[it.index-1]
	}

	kv = &bytesKeyVal{key, value, prevValue}
	it.index++

	return kv, false
}
1352570
func RetryUntilSucceed(action func() error, desc string, ctx context.Context, timeout time.Duration) {
	ctxCompleted := false
	stop := make(chan bool)
	defer close(stop)
	go func() {
		select {
		case <-ctx.Done():
			ctxCompleted = true
		case <-stop:
		}
	}()
	for {
		log.Debugf("Start %s", desc)
		err := action()
		if err == nil {
			log.Debugf("Completed %s", desc)
			return
		}
		if ctxCompleted {
			log.Debugf("Stop retrying %s", desc)
			return
		}
		log.Debugf("Failed to %s: %+v, retrying in %v", desc, err, timeout)
		time.Sleep(timeout)

	}
}
650511
func Retry(attempts int, callback func() error) (err error) {
	return RetryAfter(attempts, callback, 0)
}
1256237
func (s *ClusterRerouteService) RetryFailed(retryFailed bool) *ClusterRerouteService {
	s.retryFailed = &retryFailed
	return s
}
128707
func (b *Boxer) BoxMessage(ctx context.Context, msg chat1.MessagePlaintext,
	membersType chat1.ConversationMembersType,
	signingKeyPair libkb.NaclSigningKeyPair, info *types.BoxerEncryptionInfo) (res chat1.MessageBoxed, err error) {
	defer b.Trace(ctx, func() error { return err }, "BoxMessage")()
	tlfName := msg.ClientHeader.TlfName
	if len(tlfName) == 0 {
		return res, NewBoxingError("blank TLF name given", true)
	}
	version, err := b.GetBoxedVersion(msg)
	if err != nil {
		return res, err
	}
	if err = b.attachMerkleRoot(ctx, &msg, version); err != nil {
		return res, err
	}
	if info == nil {
		info = new(types.BoxerEncryptionInfo)
		if *info, err = b.GetEncryptionInfo(ctx, &msg, membersType, signingKeyPair); err != nil {
			return res, err
		}
		if len(msg.ClientHeader.TlfName) == 0 {
			msg := fmt.Sprintf("blank TLF name received: original: %s canonical: %s", tlfName,
				msg.ClientHeader.TlfName)
			return res, NewBoxingError(msg, true)
		}
	}
	boxed, err := b.box(ctx, msg, info.Key, info.EphemeralSeed, info.SigningKeyPair, info.Version,
		info.PairwiseMACRecipients)
	if err != nil {
		return res, NewBoxingError(err.Error(), true)
	}
	return boxed, nil
}
190497
func DecryptB64(mctx libkb.MetaContext, teamID keybase1.TeamID, boxB64 string) (res stellar1.RelayContents, err error) {
	pack, err := base64.StdEncoding.DecodeString(boxB64)
	if err != nil {
		return res, fmt.Errorf("error decoding relay box: %v", err)
	}
	var box stellar1.EncryptedRelaySecret
	err = libkb.MsgpackDecode(&box, pack)
	if err != nil {
		return res, err
	}
	appKey, err := getKeyForDecryption(mctx, teamID, box.Gen)
	if err != nil {
		return res, err
	}
	return decrypt(box, appKey)
}
956207
func (lc *LightningChannel) RemoteNextRevocation() *btcec.PublicKey {
	lc.RLock()
	defer lc.RUnlock()

	return lc.channelState.RemoteNextRevocation
}
1188928
func (it *ValIterator) GetNext(outVal interface{}) (stop bool) {
	if m, ok := outVal.(map[string]interface{}); ok {
		ok = it.Delegate.ScanMap(m)
		return !ok //if not ok than stop
	}

	_, ptrs := structs.ListExportedFieldsPtrs(outVal, cqlExported)
	ok := it.Delegate.Scan(ptrs...)
	return !ok //if not ok than stop
}
229951
func (ctx *bytesKeyIterator) GetNext() (key string, rev int64, stop bool) {
	if ctx.index >= ctx.len {
		return "", 0, true
	}

	key = string(ctx.resp.Kvs[ctx.index].Key)
	rev = ctx.resp.Kvs[ctx.index].ModRevision
	ctx.index++

	return key, rev, false
}
856947
func (it *bytesKeyIterator) GetNext() (key string, rev int64, lastReceived bool) {
	if it.err != nil {
		return "", 0, true
	}
	if it.index >= len(it.keys) {
		if it.cursor == 0 {
			return "", 0, true
		}
		var err error
		it.keys, it.cursor, err = scanKeys(it.db, it.pattern, it.cursor)
		if err != nil {
			it.err = err
			it.db.Errorf("GetNext() failed: %s (pattern %s)", err.Error(), it.pattern)
			return "", 0, true
		}
		if len(it.keys) == 0 {
			return "", 0, it.cursor == 0
		}
		it.index = 0
	}

	key = it.keys[it.index]
	if it.trimPrefix != nil {
		key = it.trimPrefix(key)
	}
	it.index++

	return key, 0, false
}
234520
func retryUntilReady(ctx context.Context, timeout time.Duration, cb func(context.Context) error) error {
	ctx, cancel := clock.WithTimeout(ctx, timeout)
	defer cancel()

	for {
		select {
		case <-ctx.Done():
			return ErrProcessingTimeout
		default:
		}

		switch err := cb(ctx); {
		case err == nil:
			return nil
		case err == context.DeadlineExceeded:
			continue // this may be short RPC deadline, try again
		case grpc.Code(err) == codes.FailedPrecondition: // the instance is not ready
			logging.Warningf(ctx, "cipd: %s", humanErr(err))
			if clock.Sleep(clock.Tag(ctx, "cipd-sleeping"), retryDelay).Incomplete() {
				return ErrProcessingTimeout
			}
		default:
			return humanErr(err)
		}
	}
}