Avoid race condition around event loop stop and restart