Merge "Fix potential unexpected behavior due to concurrent file writing." into main