IBM / sarama

Sarama is a Go library for Apache Kafka.
MIT License
11.21k stars 1.73k forks source link

Will handling response this way result in subsequent requests all being mishandled? #2918

Closed AlexanderJLiu closed 1 month ago

AlexanderJLiu commented 1 month ago

https://github.com/IBM/sarama/blob/3fad210bda77ba9ca0a7900a13ed996199c7707f/broker.go#L1164-L1171

In the code above, if a response processing fails in the connection, subsequent responses will not be correctly handled. Because "dead" is assigned the value "error," it will not be set to nil again.

Why is it designed this way here, or is my understanding incorrect?

AlexanderJLiu commented 1 month ago

FROM: Evan Huus

image

Make dead brokers die harder

When a broker gets an error trying to receive a response (either from the
network layer, or from failing to parse the minimal global header), it should
just abandon ship and die. Save that error and return it immediately for any
further requests we might have made.

- The vast majority of the time the connection is going to be hosed anyways, if
nothing else by being out-of-sync on correlation IDs (which we don't handle
and which doesn't seem particularly urgent).
- All of Sarama's built-in callers (producer/consumer/offset-manager)
immediately `Close` a broker when they receive one of these errors anyways, so
all this does is speed up that in the common case.

*If* one of these errors is recoverable, and *if* there is user-space code
somewhere which actually tries to recover in one of those cases, then that code
would break.

This neatly satisfies one of the XXX comments I left in about this issue from
way back in 2013. The TODOs about correlation ID matching are still present.