Moved log sync before message queue flushing

There still was a small race condition window.