Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net"
"sync"
Expand Down Expand Up @@ -576,6 +577,10 @@ func (w *Writer) Close() error {
w.transport.CloseIdleConnections()
}

errorsCount := w.stats().errors.snapshot()
if errorsCount > 0 {
return fmt.Errorf("failed to close gracefully, %d errors occurred", errorsCount)
}
return nil
}

Expand Down
14 changes: 14 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func TestWriter(t *testing.T) {
function: testWriterClose,
},

{
scenario: "closing a writer with errors should return error",
function: testWriterCloseWithErrors,
},

{
scenario: "writing 1 message through a writer using round-robin balancing produces 1 message to the first partition",
function: testWriterRoundRobin1,
Expand Down Expand Up @@ -223,6 +228,15 @@ func testWriterClose(t *testing.T) {
}
}

func testWriterCloseWithErrors(t *testing.T) {
w := newTestWriter(WriterConfig{})
w.stats().errors.observe(1)

if err := w.Close(); err == nil {
t.Error("expected error, but got nil")
}
}

func testWriterRequiredAcksNone(t *testing.T) {
topic := makeTopic()
createTopic(t, topic, 1)
Expand Down