fixed race condition with periodical flush and ack_msg (similar to flush+save_msg)