shadow: fix race conditions