ENG-5939: Wait for snapshot sync task to finish on close

This avoids race between the sync task and the closing of the file.