Remove race condition in writing out encrypted data.