You have a race condition here where you read and then flush later. You need to put the sync around where you do the first read of the logs.