Skip to content

Commit 03c9660

Browse files
committed
Add some refreshing comments
1 parent dd0dbf0 commit 03c9660

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

plugins/outputs/cloudwatchlogs/cloudwatchlogs.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,13 @@ func (e *structuredLogEvent) Done() {}
334334
type cwDest struct {
335335
pusher *pusher.Pusher
336336
sync.Mutex
337-
isEMF bool
338-
retryer *retryer.LogThrottleRetryer
337+
isEMF bool
338+
retryer *retryer.LogThrottleRetryer
339+
340+
// refCount keeps track of how many LogSrc objects are referencing
341+
// this cwDest object at any given time. Once there are no more
342+
// references, the cwDest object stops itself, closing all goroutines,
343+
// and it can no longer be used
339344
refCount int
340345
stopped bool
341346
onStopFunc func()
@@ -344,6 +349,9 @@ type cwDest struct {
344349
var _ logs.LogDest = (*cwDest)(nil)
345350

346351
func (cd *cwDest) Publish(events []logs.LogEvent) error {
352+
if cd.stopped {
353+
return fmt.Errorf("cannot publish events: destination has been stopped")
354+
}
347355
for _, e := range events {
348356
if !cd.isEMF {
349357
msg := e.Message()
@@ -381,6 +389,10 @@ func (cd *cwDest) stop() {
381389
}
382390

383391
func (cd *cwDest) AddEvent(e logs.LogEvent) {
392+
if cd.stopped {
393+
// cannot add event, destination has been stopped
394+
return
395+
}
384396
// Drop events for metric path logs when queue is full
385397
if cd.isEMF {
386398
cd.pusher.AddEventNonBlocking(e)

0 commit comments

Comments
 (0)