Skip to content

Registry.Gather should turn panics into errors #1900

@bboreham

Description

@bboreham

This code:

collectWorker := func() {
for {
select {
case collector := <-checkedCollectors:
collector.Collect(checkedMetricChan)

will end the whole program if the collector panics, since it is run on a background goroutine. This may be an unpleasant lesson.

As a comparison, the net/http package handles panics anywhere in the serving code, although the author says they should have made this opt-in.

I note that ErrGroup added then removed this feature; reading the thread I understand that the reasons were (1) it could take a long time to reveal the error and (2) the stack trace was lost. Gather can fail immediately on panic, and can supply the stack trace in the error it returns.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions