Fix bug in publish_impl when using port 0