Skip to content

Fix for panic when RequiredAcks is set to RequireNone #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 29, 2020
Merged
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
2 changes: 2 additions & 0 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ func (p async) await(ctx context.Context) (Response, error) {
select {
case x := <-p:
switch v := x.(type) {
case nil:
return nil, nil // A nil response is ok (e.g. when RequiredAcks is None)
case Response:
return v, nil
case error:
Expand Down
27 changes: 27 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func TestWriter(t *testing.T) {
scenario: "setting a non default balancer on the writer",
function: testWriterSetsRightBalancer,
},
{
scenario: "setting RequiredAcks to None in Writer doesn't cause a panic",
function: testWriterRequiredAcksNone,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -83,6 +87,29 @@ func testWriterClose(t *testing.T) {
}
}

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

w := &Writer{
Addr: TCP("localhost:9092"),
Topic: topic,
Balancer: &RoundRobin{},
RequiredAcks: RequireNone,
}
defer w.Close()

msg := Message{
Key: []byte("ThisIsAKey"),
Value: []byte("Test message for required acks test")}

err := w.WriteMessages(context.Background(), msg)
if err != nil {
t.Fatal(err)
}
}

func testWriterSetsRightBalancer(t *testing.T) {
const topic = "test-writer-1"
balancer := &CRC32Balancer{}
Expand Down