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.

Activity

added a commit that references this issue on Apr 14, 2020

Fixed segmentio#428 by making reader.read respect context closure.

4d6d176
Antonboom

Antonboom commented on Feb 3, 2021

@Antonboom

+1

SuddenGunter

SuddenGunter commented on May 30, 2023

@SuddenGunter

had the same issue
any fix for it?

rhasanoff

rhasanoff commented on Jan 18, 2024

@rhasanoff

Having the same issue +1

Gewinum

Gewinum commented on Oct 26, 2024

@Gewinum

i've got the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @achille-roussel@feldgendler@SuddenGunter@Antonboom@rhasanoff

    Issue actions

      Reader.Close hangs for ReaderConfig.MaxWait · Issue #428 · segmentio/kafka-go