Avoid race condition in session key generation