Skip to content

Commit

Permalink
fix(m365 receiver): Add nil check to shutdown (#1369)
Browse files Browse the repository at this point in the history
* add nil check to shutdown

* brandons feedback
  • Loading branch information
dpaasman00 authored Dec 4, 2023
1 parent 18166ed commit a9d1b73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion receiver/m365receiver/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ func (l *m365LogsReceiver) Start(ctx context.Context, host component.Host) error

func (l *m365LogsReceiver) Shutdown(ctx context.Context) error {
l.logger.Debug("shutting down logs receiver")
l.cancel()
if l.cancel != nil {
l.cancel()
}
l.wg.Wait()
return l.checkpoint(ctx)
}
Expand Down Expand Up @@ -285,6 +287,9 @@ func (l *m365LogsReceiver) transformLogs(now pcommon.Timestamp, audit *auditMeta

// sets the checkpoint
func (l *m365LogsReceiver) checkpoint(ctx context.Context) error {
if l.record == nil {
return nil
}
bytes, err := json.Marshal(l.record)
if err != nil {
return fmt.Errorf("unable to write checkpoint: %w", err)
Expand Down
5 changes: 4 additions & 1 deletion receiver/m365receiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ func (m *m365Scraper) start(ctx context.Context, host component.Host) error {
}

func (m *m365Scraper) shutdown(_ context.Context) error {
return m.client.shutdown()
if m.client != nil {
return m.client.shutdown()
}
return nil
}

// retrieves data, builds metrics & emits them
Expand Down

0 comments on commit a9d1b73

Please sign in to comment.