uw-labs/substrate

[bug] race condition in nats streaming sink

Closed this issue · 0 comments

In rare occurrences the ack callback send to the go channel natsAcks (https://github.com/uw-labs/substrate/blob/master/natsstreaming/nats_streaming.go#L122) is observed before the send on the toAck channel (https://github.com/uw-labs/substrate/blob/master/natsstreaming/nats_streaming.go#L127). This causes a send of an error on the go channel in line https://github.com/uw-labs/substrate/blob/master/natsstreaming/nats_streaming.go#L90. However, because of the way the loops terminate, this error never becomes observable, as the function never terminates (this is to do with the deferred cancel and waitgroup calls). I'll send an example that fixed this issue locally.

My proposal is that we don't check for these ids lining up. I don't see any practical reason for doing so. I therefore propose removing the go routine at https://github.com/uw-labs/substrate/blob/master/natsstreaming/nats_streaming.go#L82 and just sending the ack confirmation for the message in the callback (closing over it).