Skip to content

Commit

Permalink
Send to chan with ctx check
Browse files Browse the repository at this point in the history
  • Loading branch information
alok87 committed Mar 20, 2021
1 parent ff56abd commit 2a4f7a4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/redshiftbatcher/batch_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,18 @@ func (b *batchProcessor) Process(
"%s, error(s) occured in processing (sending err)", b.topic,
)
b.handleShutdown()
errChan <- errors

// send to channel with context check, fix #170
select {
case <-session.Context().Done():
klog.V(2).Infof(
"%s: processor returning, session ctx done",
b.topic,
)
return
case errChan <- errors:
}

klog.Errorf(
"%s, error(s) occured: %+v, processor shutdown.",
b.topic,
Expand All @@ -512,7 +523,16 @@ func (b *batchProcessor) Process(
}
err := b.signalLoad(resp)
if err != nil {
errChan <- err
// send to channel with context check, fix #170
select {
case <-session.Context().Done():
klog.V(2).Infof(
"%s: processor returning, session ctx done",
b.topic,
)
return
case errChan <- err:
}
klog.Errorf(
"%s, error signalling: %v, processor shutdown.",
b.topic,
Expand Down

0 comments on commit 2a4f7a4

Please sign in to comment.