varnishcache / varnish-cache

Varnish Cache source code repository
https://www.varnish-cache.org
Other
3.63k stars 372 forks source link

varnishncsa: %O and %b contain entire response size even when the connection was interrupted #4181

Closed sbraz closed 2 days ago

sbraz commented 4 days ago

Expected Behavior

Hello,

The doc for %O says:

In client mode, total bytes sent to client

So if bytes were not sent, I do not expect them to be counted.

Current Behavior

Currently, %O and %b always return the size of the entire response, even when the connection is interrupted by the client after a fraction of seconds.

Possible Solution

No response

Steps to Reproduce (for bugs)

  1. Run varnishncsa -F "%b %O"
  2. Run curl -m 0.5 http://localhost/some/very/large/file
  3. curl reports Operation timed out after 500 milliseconds with xxx out of yyy bytes received
  4. Varnish reports %b to be yyy bytes and %O is constant as well, no matter how much data is actually sent to the client

Context

I am currently attempting to count bytes sent to clients to determine which IPs are responsible for most of the traffic and I would like to have a reliable of doing this by analyzing Varnish's logs.

Varnish Cache version

varnishd (varnish-7.1.1 revision 7cee1c581bead20e88d101ab3d72afb29f14d87a)

Operating system

Debian 12

Source of binary packages used (if any)

https://packages.debian.org/bookworm/varnish

sbraz commented 4 days ago

I just saw 51176640603b123a38b49ae271cb9c9de9df1d28 which seemed to fix a very similar problem. Could it be a new regression?

dridi commented 2 days ago

Not really a regression. This is accurate from Varnish's perspective of successfully "sending" bytes to the kernel, but what happens beyond that is out of our control.

There's probably non-portable room for improvement, but this is the current state of affairs.

nigoroll commented 2 days ago

As @dridi explained. Otherwise: PRs welcome