github.com/segmentio/kafka-go consumer报以下异常 the kafka reader got an unknown error reading partition 0 of timeout01 at offset 4: read tcp [localhost]:6210->[localhost]:9092: i/o timeout
示例:
reader :=kafka.NewReader(kafka.ReaderConfig{
Brokers: []string{"localhost:9092"},
GroupID: "consumer-timeout",
Topic: "timeout01",
ReadBatchTimeout: 500 * time.Millisecond,
MaxWait: 500 * time.Millisecond,
CommitInterval: 20 * time.Second,
SessionTimeout: 30 * time.Second,
HeartbeatInterval: 3 * time.Second,
RetentionTime: 7 * 24 * time.Hour,
StartOffset: kafka.FirstOffset,
})
for {
kafkaMsg,err :=reader.ReadMessage(context.Background())
if err!=nil {
fmt.Println("err:",err)
continue
}
fmt.Println("message:",kafkaMsg)
}
问题修复方案:
MaxWait 修改为 3*time.Second
max_wait不是fetch data wait time,包中仅reader.go 1493行代码中,conn.ReadBatchWith()中超时作用,设置过短会导致io/timeout异常,conn频繁以为异常重建