# Buggy code
def zeroconf_register(self, reg_type, name=None, port=None, txt_record=None):
    """
    Registers a new service with Zeroconf/Bonjour/Avahi.

    :param reg_type: type of service to register, e.g. "_gntp._tcp"
    :param name: displayable name of the service, if not given defaults to the OctoPrint instance name
    :param port: port to register for the service, if not given defaults to OctoPrint's (public) port
    :param txt_record: optional txt record to attach to the service, dictionary of key-value-pairs
    """

    if not pybonjour:
        return

    if not name:
        name = self.get_instance_name()
    if not port:
        port = self.port

    params = dict(name=name, regtype=reg_type, port=port)
    if txt_record:
        params["txtRecord"] = pybonjour.TXTRecord(txt_record)

    key = (reg_type, port)
    self._sd_refs[key] = pybonjour.DNSServiceRegister(**params)
    self._logger.info("Registered {name} for {reg_type}".format(**locals()))


# Traceback (BonjourError)
2018-10-13 18:40:48,117 - octoprint.plugin - ERROR - Error while calling plugin discovery
Traceback (most recent call last):
File "/root/OctoPrint/venv/lib/python2.7/site-packages/OctoPrint-1.3.9-py2.7.egg/octoprint/plugin/__init__.py", line 225, in call_plugin
result = getattr(plugin, method)(*args, **kwargs)
File "/root/OctoPrint/venv/lib/python2.7/site-packages/OctoPrint-1.3.9-py2.7.egg/octoprint/plugins/discovery/__init__.py", line 143, in on_startup
self.zeroconf_register("_http._tcp", self.get_instance_name(), txt_record=self._create_http_txt_record_dict())
File "/root/OctoPrint/venv/lib/python2.7/site-packages/OctoPrint-1.3.9-py2.7.egg/octoprint/plugins/discovery/__init__.py", line 197, in zeroconf_register
self._sd_refs[key] = pybonjour.DNSServiceRegister(**params)
File "/mnt/local/lib/python2.7/site-packages/pybonjour.py", line 1132, in DNSServiceRegister
None)
File "/mnt/local/lib/python2.7/site-packages/pybonjour.py", line 286, in _errcheck
raise cls(result)
BonjourError: (-65548, 'name conflict')

# Fixed code
def zeroconf_register(self, reg_type, name=None, port=None, txt_record=None):
    """
    Registers a new service with Zeroconf/Bonjour/Avahi.

    :param reg_type: type of service to register, e.g. "_gntp._tcp"
    :param name: displayable name of the service, if not given defaults to the OctoPrint instance name
    :param port: port to register for the service, if not given defaults to OctoPrint's (public) port
    :param txt_record: optional txt record to attach to the service, dictionary of key-value-pairs
    """

    if not pybonjour:
        return

    if not name:
        name = self.get_instance_name()
    if not port:
        port = self.port

    params = dict(name=name, regtype=reg_type, port=port)
    if txt_record:
        params["txtRecord"] = pybonjour.TXTRecord(txt_record)

    key = (reg_type, port)

    counter = 0
    while True:
        try:
            self._sd_refs[key] = pybonjour.DNSServiceRegister(**params)
            self._logger.info("Registered '{name}' for {regtype}".format(**params))
            return True
        except pybonjour.BonjourError as be:
            if be.errorCode == pybonjour.kDNSServiceErr_NameConflict:
                # Name already registered by different service, let's try a counter postfix. See #2852
                counter += 1
                params["name"] = "{} ({})".format(name, counter)
            else:
                raise