Fix race condition in the router