fix cleanup to sync/close file after reader exit