Commit c5839cb
Fix pool buffer bypass caused by *os.File WriterTo
On Go 1.26+, *os.File implements WriterTo. When ioCopier's reader is an
*os.File (the common case for commandStage), io.CopyBuffer detects
WriterTo and calls File.WriteTo instead of using the provided pool
buffer. File.WriteTo's sendfile path fails (the dest is not a network
connection), so it falls back to genericWriteTo → io.Copy, which
allocates a fresh 32KB buffer on every call — defeating the sync.Pool
entirely.
Fix: wrap the reader in readerOnly{} to strip all interfaces except
Read, forcing io.CopyBuffer to use the pool buffer.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 22c71ee commit c5839cb
1 file changed
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
45 | 55 | | |
46 | 56 | | |
47 | 57 | | |
| |||
0 commit comments