Skip to content

Fix double-counting of bytes in httpFancyWriter.ReadFrom with tee#1078

Closed
Bahtya wants to merge 1 commit intogo-chi:masterfrom
Bahtya:fix/readfrom-double-count
Closed

Fix double-counting of bytes in httpFancyWriter.ReadFrom with tee#1078
Bahtya wants to merge 1 commit intogo-chi:masterfrom
Bahtya:fix/readfrom-double-count

Conversation

@Bahtya
Copy link
Copy Markdown

@Bahtya Bahtya commented Apr 5, 2026

Problem

When a tee writer is set, ReadFrom uses io.Copy(&f.basicWriter, r) which routes data through basicWriter.Write(). That method already increments b.bytes (line 112). Then line 212 also increments f.basicWriter.bytes += int(n), double-counting the same bytes.

Solution

Remove the redundant f.basicWriter.bytes += int(n) line in the tee branch. Write() already handles the counting.

The non-tee branch (line 217-218) is correct as-is because rf.ReadFrom() calls the underlying ResponseWriter directly, bypassing basicWriter.Write().

Fixes #1067

When tee is set, ReadFrom uses io.Copy(&f.basicWriter, r) which routes
through basicWriter.Write() — already incrementing bytes. The subsequent
f.basicWriter.bytes += int(n) line then double-counts the same bytes.

Remove the redundant increment since Write() already handles it.

Fixes #1067
@Bahtya Bahtya closed this by deleting the head repository Apr 6, 2026
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.

httpFancyWriter.ReadFrom double-counts BytesWritten when Tee is set

1 participant