apache / pulsar-client-go

Apache Pulsar Go Client Library
https://pulsar.apache.org/
Apache License 2.0
659 stars 336 forks source link

[Issue 1258][producer] Avoid a data race when flushing with load #1261

Closed Gilthoniel closed 3 months ago

Gilthoniel commented 3 months ago

Fixes #1258

Motivation

While flushing, the data channel is switched if a new allocated one which can cause the loss of messages because the length can be zero which would stop the procedure and at the same time a new message can be sent to the channel.

Modifications

Instead of allocating a new channel, it empties the existing one up to the length of the buffer of the channel before proceeding with the flush.

Verifying this change

This change is already covered by existing tests, such as TestFlushInProducer.

Documentation