Fix race condition in multi-threaded message routing