-     * positive reply about the operation performed. */
-    server.aofbuf = sdscatlen(server.aofbuf,buf,sdslen(buf));
+     * positive reply about the operation performed.
+     *
+     * Note, we don't add stuff in the AOF buffer if aof_wait_rewrite is
+     * non zero, as this means we are starting with a new AOF and the
+     * current one is meaningless (this happens for instance after
+     * a slave resyncs with its master). */
+    if (!server.aof_wait_rewrite) {
+        server.aofbuf = sdscatlen(server.aofbuf,buf,sdslen(buf));
+    }