bugsnag / bugsnag-go

Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
https://docs.bugsnag.com/platforms/go
MIT License
204 stars 69 forks source link

Goroutine kicked off at import time #247

Open NeilLuno opened 2 weeks ago

NeilLuno commented 2 weeks ago

Describe the bug

At https://github.com/bugsnag/bugsnag-go/blob/master/v2/notifier.go#L7, newPublisher kicks off a goroutine at import time. This means that just importing github.com/bugsnag/bugsnag-go/v2 results in a goroutine. As far as I can tell, there's no way to terminate the goroutine.

While this isn't a problem for us from a performance point of view, it does mean that when using go.uber.org/goleak, we have to add an exception for bugsnag-go. It's not the end of the world, but it's a nuisance.

Steps to reproduce

See example program below.

Environment

Example Repo

Example code snippet

// test.go
package main

import (
    "fmt"

    _ "github.com/bugsnag/bugsnag-go/v2"
    "go.uber.org/goleak"
)

func main() {
    err := goleak.Find()
    fmt.Println(err) // Should print nil. Prints "found unexpected goroutines:..."
}
Error messages: ``` ```
mclack commented 3 days ago

Hi @NeilLuno

We've discussed this, and as a result we have added a task to our backlog to see whether we can start this goroutine later. I don't currently have an ETA on when this will be properly looked into, but we will make sure to post any updates on this thread.

For additional context, the behaviour for the asynchronous sending of events to BugSnag changed in the v2.5.0 release of bugsnag-go. Instead of previously where a goroutine would be triggered for every event report, a single goroutine is now started by BugSnag, and this acts as a queue for events to be sent from.

NeilLuno commented 3 days ago

Hi @mclack. I really appreciate the response. Agree that one goroutine is better than many. We've managed to find a workaround in the meantime.