Skip to content

Conversation

@EmperorGentoo
Copy link
Contributor

The proxy agent faces an ENHANCE_YOUR_CALM error leading to closed connections. A similar problem has been discussed in this article as well: https://blog.cloudflare.com/go-and-enhance-your-calm/

The issue seems to be with how resp.Body.Close() works in golang.

}
defer proxyResp.Body.Close()
defer func() {
io.Copy(io.Discard, proxyResp.Body)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is safe to do in the case of listing the pending requests.

The response from the proxy could be arbitrarily large, and in fact, being too large is probably the main way for this issue to be hit in this particular case.

If the response is very large, then the agent will have to read through the entire response body before it attempts to list the pending requests again.

That means we could be introducing an arbitrarily large delay (assuming an arbitrarily long response) that blocks all requests for this backend from being processed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed draining the response body from List Pending Requests and kept it in the agent/response.

Given the nature of our traffic, I suppose that is the major contributor. We don't see any ENHANCE_YOUR_CALM errors post draining there.

@ojarjur ojarjur merged commit cd74c27 into google:master Nov 18, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants