Fix a race condition when waiting for containers.