Language: Go
Label: safe
CWE: CWE-835 \u2014 Loop with Unreachable Exit Condition ('Infinite Loop')
The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop.

Code:
func (q *ListObjectsQuery) Execute(
	ctx context.Context,
	req *openfgav1.ListObjectsRequest,
) (*ListObjectsResponse, error) {

	resultsChan := make(chan ListObjectsResult, 1)
	maxResults := q.listObjectsMaxResults
	if maxResults > 0 {
		resultsChan = make(chan ListObjectsResult, maxResults)
	}

	timeoutCtx := ctx
	if q.listObjectsDeadline != 0 {
		var cancel context.CancelFunc
		timeoutCtx, cancel = context.WithTimeout(ctx, q.listObjectsDeadline)
		defer cancel()
	}

	resolutionMetadata := reverseexpand.NewResolutionMetadata()

	err := q.evaluate(timeoutCtx, req, resultsChan, maxResults, resolutionMetadata)
	if err != nil {
		return nil, err
	}

	objects := make([]string, 0)

	for {
		select {

		case <-timeoutCtx.Done():
			q.logger.WarnWithContext(
				ctx, fmt.Sprintf("list objects timeout after %s", q.listObjectsDeadline.String()),
			)
			return &ListObjectsResponse{
				Objects:            objects,
				ResolutionMetadata: *resolutionMetadata,
			}, nil

		case result, channelOpen := <-resultsChan:
			if result.Err != nil {
				if errors.Is(result.Err, serverErrors.AuthorizationModelResolutionTooComplex) {
					return nil, result.Err
				}

				return nil, serverErrors.HandleError("", result.Err)
			}

			if !channelOpen {
				return &ListObjectsResponse{
					Objects:            objects,
					ResolutionMetadata: *resolutionMetadata,
				}, nil
			}
			objects = append(objects, result.ObjectID)
		}
	}
}