Skip to content

Reader.Close hangs for ReaderConfig.MaxWait #428

@feldgendler

Description

@feldgendler

Describe the bug
After reading once, Reader.Close hangs until the end of a MaxWait duration.

Kafka Version
2.3.0

To Reproduce

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/segmentio/kafka-go"
)

func main() {
	reader := kafka.NewReader(kafka.ReaderConfig{
		Brokers: []string{"localhost:9092"}, // assuming a running Kafka instance
		Topic:   "test", // does not need to exist
		MaxWait: time.Hour,
	})

	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()

	fmt.Println("Trying to read...")
	_, _ = reader.FetchMessage(ctx)

	fmt.Println("Closing reader...")
	reader.Close()

	fmt.Println("Test passed")
}

Expected behavior
Reader.Close should close the connection and return immediately.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions