Fix race condition in handlers.