diff --git a/connection_unix.go b/connection_unix.go index b6516ec7a..3ccac4ab1 100644 --- a/connection_unix.go +++ b/connection_unix.go @@ -326,11 +326,10 @@ func (c *conn) Next(n int) (buf []byte, err error) { head, tail := c.inboundBuffer.Peek(n) defer c.inboundBuffer.Discard(n) //nolint:errcheck c.loop.cache.Reset() + c.loop.cache.Write(head) if len(head) >= n { - c.loop.cache.Write(head) return c.loop.cache.Bytes(), err } - c.loop.cache.Write(head) c.loop.cache.Write(tail) if inBufferLen >= n { return c.loop.cache.Bytes(), err diff --git a/connection_windows.go b/connection_windows.go index ead4a253c..745028434 100644 --- a/connection_windows.go +++ b/connection_windows.go @@ -165,11 +165,10 @@ func (c *conn) Next(n int) (buf []byte, err error) { head, tail := c.inboundBuffer.Peek(n) defer c.inboundBuffer.Discard(n) //nolint:errcheck c.loop.cache.Reset() + c.loop.cache.Write(head) if len(head) >= n { - c.loop.cache.Write(head) return c.loop.cache.Bytes(), err } - c.loop.cache.Write(head) c.loop.cache.Write(tail) if inBufferLen >= n { return c.loop.cache.Bytes(), err