Fix an issue where a race condition occured and caused data curroption