[improve][broker] Close connection when close consumer write fails - #25520
Conversation
The change looks ok, but I have doubts whether there could be a scenario where the command doesn't reach the client and there's no other error / exception in the logs. Any unhandled exception would result in the connection being closed by this code in exceptionCaught. |
Sorry for the noise. Yes, this PR helps. #15382 was a similar change to Ping/Pong. |
Btw. there are also other cases where the consumer might be alive on the client side (until the next Ping command) which are caused by different reason than what is handled by this PR. They happen especially in Kubernetes environments. One of the unresolved issues in Kubernetes is kubernetes/kubernetes#104098 (this was an issue that Michael was digging into a few years ago) which is challenging. IIRC, the main scenario was rebooting a k8s node. That resulted in problems in many Pulsar clients and stale connections. The problem at that time with k8s node reboots was mitigated with #20026. The previous improvement was #15382, but that has the latency of the keep alive interval. A long list of related issues in Kubernetes (list compiled with Claude):
Many of the issues are simply not easy to resolve as explained in the discussion that Michael had on the issue (for example comment and the following one are at the gist of the problem). There's also a reference https://blog.cloudflare.com/when-tcp-sockets-refuse-to-die/ in the issue comments. |
|
Some additional details from Claude:
It seems that there's a recommendation to replace kube-proxy with Cilium. This option seems to be available also on all major cloud provider managed k8s services (EKS, GKE and AKS). The default option is kube-proxy in most cases. Claude's comments:
|
|
@lhotari Thanks for your share, this is useful for me! |
…pache#25520) (cherry picked from commit f688ff7)
…pache#25520) (cherry picked from commit f688ff7) (cherry picked from commit 90ef622)
…pache#25520) (cherry picked from commit f688ff7) (cherry picked from commit 15b4327)
…pache#25520) (cherry picked from commit f688ff7)
…pache#25520) (cherry picked from commit f688ff7)
Fix #25146
Motivation
When the broker asks a client to close a consumer, if the
CloseConsumercommand does not reach the client, the client may keep the consumer alive locally while the broker has already removed it, leading to a silent inconsistent state.Modifications
CloseConsumerfailsCloseConsumerwrite pathVerifying this change
This change added tests and can be verified as follows:
ServerCnxTestcase for failedCloseConsumerwrites to ensure the connection is closedDoes this pull request potentially affect one of the following parts: