Fix race condition closing recording.