fix: WriteTo empty buffer handling - #182
Conversation
pires
left a comment
There was a problem hiding this comment.
Thank you for your contribution.
IMO we should take the buffer-clearing optimization but do not discard an empty bufio.Reader without accounting for its pending error state. Also, and pretty please, add tests that assert both memory cleanup and preservation of underlying read errors.
| } | ||
|
|
||
| // If the buffer has been drained, copy directly from conn. | ||
| if p.bufReader.Buffered() == 0 { |
There was a problem hiding this comment.
IIUC Buffered() == 0 only means no bytes remain; the reader can still hold a pending error from an underlying Read that returned (n > 0, err). Clearing bufReader and copying directly from conn discards that error.
There was a problem hiding this comment.
Thanks for the comment, will try to find time to fix it over the weekends
There was a problem hiding this comment.
@pires I added check for pending errors and tests that cover this case
Added check for buffer size and cleaning of the buffer after reading.
This PR closes #181