diff --git a/contrib/codecs/rdwr/codec.go b/contrib/codecs/rdwr/codec.go
index f02a0137b1889e90eb6d152002ac372863a867f1..b7774d8e5127af77ae210c02f6cbdcfc3e5b924b 100644
--- a/contrib/codecs/rdwr/codec.go
+++ b/contrib/codecs/rdwr/codec.go
@@ -90,8 +90,14 @@ func (c *Codec) Write(p []byte) (n int, err error) {
 func (c *Codec) Flush() (err error) {
 	c.wrLock.Lock()
 	defer c.wrLock.Unlock()
-	c.wr.WriteByte('\n')
-	return c.wr.Flush()
+	if c.wr.Buffered() > 0 {
+		c.wr.WriteByte('\n')
+		err = c.wr.Flush()
+		if err != nil {
+			return err
+		}
+	}
+	return nil
 }
 
 // Closed returns a channel which is closed when the connection is closed.