@@ -35,17 +35,17 @@ type Neli interface {
3535}
3636
3737type neli struct {
38- config Config
39- scribe scribe.Scribe
40- consumer KafkaConsumer
41- producer KafkaProducer
42- pollDeadline concurrent.Deadline
43- lastReceived concurrent.AtomicCounter
44- isAssigned concurrent.AtomicCounter
45- isLeader concurrent.AtomicCounter
46- barrier Barrier
47- state concurrent.AtomicReference
48- stateMutex sync.Mutex
38+ config Config
39+ scribe scribe.Scribe
40+ consumer KafkaConsumer
41+ producer KafkaProducer
42+ pollDeadline concurrent.Deadline
43+ lastReceived concurrent.AtomicCounter
44+ isAssigned concurrent.AtomicCounter
45+ isLeader concurrent.AtomicCounter
46+ barrier Barrier
47+ state concurrent.AtomicReference
48+ stateMutex sync.Mutex
4949 deliveryHandlerDone chan int
5050}
5151
@@ -76,14 +76,14 @@ func New(config Config, barrier ...Barrier) (Neli, error) {
7676 return nil , err
7777 }
7878 n := & neli {
79- config : config ,
80- scribe : config .Scribe ,
81- lastReceived : concurrent .NewAtomicCounter (),
82- isAssigned : concurrent .NewAtomicCounter (),
83- isLeader : concurrent .NewAtomicCounter (),
84- barrier : barrierArg ,
85- pollDeadline : concurrent .NewDeadline (* config .MinPollInterval ),
86- state : concurrent .NewAtomicReference (Live ),
79+ config : config ,
80+ scribe : config .Scribe ,
81+ lastReceived : concurrent .NewAtomicCounter (),
82+ isAssigned : concurrent .NewAtomicCounter (),
83+ isLeader : concurrent .NewAtomicCounter (),
84+ barrier : barrierArg ,
85+ pollDeadline : concurrent .NewDeadline (* config .MinPollInterval ),
86+ state : concurrent .NewAtomicReference (Live ),
8787 deliveryHandlerDone : make (chan int ),
8888 }
8989
@@ -137,7 +137,7 @@ func New(config Config, barrier ...Barrier) (Neli, error) {
137137 n .producer = p
138138 go func () {
139139 defer close (n .deliveryHandlerDone )
140-
140+
141141 for event := range p .Events () {
142142 switch e := event .(type ) {
143143 case * kafka.Message :
@@ -367,15 +367,16 @@ func (n *neli) Close() error {
367367 defer func () {
368368 <- n .deliveryHandlerDone
369369 }()
370- defer func () {
371- go func () {
372- // A bug in confluent-kafka-go (#463) occasionally causes an indefinite syscall hang in Close(), after it closes
373- // the Events channel. So we delegate this to a separate goroutine — better an orphaned goroutine than a
374- // frozen harvester. (The rest of the battery will still unwind normally.)
375- n .producer .Close ()
376- }()
377- }()
378- return n .consumer .Close ()
370+
371+ // A bug in confluent-kafka-go (#463) occasionally causes an indefinite syscall hang in Close(), after it closes
372+ // the Events channel. So we delegate this to a separate goroutine — better an orphaned goroutine than a
373+ // frozen harvester. (The rest of the battery will still unwind normally.)
374+ const closeTimeout = 10 * time .Second
375+ _ , _ = performTimed (void (n .producer .Close ), closeTimeout )
376+
377+ // Similarly to the above, Consumer.Close() may also hang, and we need to cope with this until #463 is resolved.
378+ _ , err := performTimed (n .consumer .Close , closeTimeout )
379+ return err
379380}
380381
381382// Await the closing of this Neli instance.
0 commit comments