File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
plugins/outputs/cloudwatchlogs Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -334,8 +334,13 @@ func (e *structuredLogEvent) Done() {}
334334type 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 {
344349var _ logs.LogDest = (* cwDest )(nil )
345350
346351func (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
383391func (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 )
You can’t perform that action at this time.
0 commit comments