avoid race between testing and using port