diff --git a/v2/bugsnag.go b/v2/bugsnag.go index 66a5895..4e34491 100644 --- a/v2/bugsnag.go +++ b/v2/bugsnag.go @@ -48,6 +48,9 @@ func Configure(config Configuration) { readEnvConfigOnce.Do(Config.loadEnv) Config.update(&config) updateSessionConfig() + + // start delivery goroutine later than the module import time + go publisher.delivery() // Only do once in case the user overrides the default panichandler, and // configures multiple times. panicHandlerOnce.Do(Config.PanicHandler) diff --git a/v2/bugsnag_test.go b/v2/bugsnag_test.go index da72f3b..e31cbd9 100644 --- a/v2/bugsnag_test.go +++ b/v2/bugsnag_test.go @@ -151,6 +151,9 @@ func (tp *testPublisher) publishReport(p *payload) error { func (tp *testPublisher) setMainProgramContext(context.Context) { } +func (tp *testPublisher) delivery() { +} + func TestNotifySyncThenAsync(t *testing.T) { ts, _ := setup() defer ts.Close() diff --git a/v2/report_publisher.go b/v2/report_publisher.go index 6ccb17e..43937e1 100644 --- a/v2/report_publisher.go +++ b/v2/report_publisher.go @@ -3,26 +3,18 @@ package bugsnag import ( "context" "fmt" - "os" - "os/signal" - "syscall" ) type reportPublisher interface { publishReport(*payload) error setMainProgramContext(context.Context) + delivery() } func (defPub *defaultReportPublisher) delivery() { - signalsCh := make(chan os.Signal, 1) - signal.Notify(signalsCh, syscall.SIGINT, syscall.SIGTERM) - waitForEnd: for { select { - case <-signalsCh: - defPub.isClosing = true - break waitForEnd case <-defPub.mainProgramCtx.Done(): defPub.isClosing = true break waitForEnd @@ -42,10 +34,10 @@ waitForEnd: // Send remaining elements from the queue close(defPub.eventsChan) for p := range defPub.eventsChan { - if err := p.deliver(); err != nil { - // Ensure that any errors are logged if they occur in a goroutine. - p.logf("bugsnag/defaultReportPublisher.publishReport: %v", err) - } + if err := p.deliver(); err != nil { + // Ensure that any errors are logged if they occur in a goroutine. + p.logf("bugsnag/defaultReportPublisher.publishReport: %v", err) + } } } @@ -59,8 +51,6 @@ func newPublisher() reportPublisher { defPub := defaultReportPublisher{isClosing: false, mainProgramCtx: context.TODO()} defPub.eventsChan = make(chan *payload, 100) - go defPub.delivery() - return &defPub }