Skip to content

Commit 5c29de6

Browse files
committed
add additional warning on WriteMessages()
Signed-off-by: Mauro Stettler <[email protected]>
1 parent f057b1d commit 5c29de6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

writer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,12 @@ func (w *Writer) Close() error {
600600
//
601601
// The context passed as first argument may also be used to asynchronously
602602
// cancel the operation. Note that in this case there are no guarantees made on
603-
// whether messages were written to kafka. The program should assume that the
604-
// whole batch failed and re-write the messages later (which could then cause
605-
// duplicates).
603+
// whether messages were written to kafka, they might also still be written
604+
// after this method has already returned, therefore it is important to not
605+
// modify byte slices of passed messages if WriteMessages returned early due
606+
// to a canceled context.
607+
// The program should assume that the whole batch failed and re-write the
608+
// messages later (which could then cause duplicates).
606609
func (w *Writer) WriteMessages(ctx context.Context, msgs ...Message) error {
607610
if w.Addr == nil {
608611
return errors.New("kafka.(*Writer).WriteMessages: cannot create a kafka writer with a nil address")

0 commit comments

Comments
 (0)