Skip to content

BUG/RFC: CarbonserverListener.fetchData always returns a nil error leading to unreachable code #819

@drawks

Description

@drawks

While looking at some issues with the concurrency in this method I noticed that while an effort is made to keep track of and even log on errors

the final return always returns nil

return multi, nil

which means that calling code which checks for and handles errors is unreachable

if err != nil {
listener.accessLogger.Error("error while fetching the data",
zap.Error(err),
)
continue
}

I looked back through the commit history and I don't see where the caller ever used the error for controlling business logic, so I presume that the current behavior is expected, even if it isn't necessarily intended or desired.

A simple fix of returning the first error or returning a "multierror" with errors.Join(errs...) would cause a behavioral change in that the continue would now be reachable and would prevent any results from being passed into the result channel.

Overall I suspect that this entire code path could/should be rewritten to avoid some of ambiguity. Perhaps it would make more sense to pass the result channel directly to the go routines in a sort of multiproducer pattern and we could also remove some of mutex banging which brought me to this code to begin with 🤷🏽

At any rate, I'm looking for some comments/feedback before I float an MR which introduces any behavioral change

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions