# Buggy code
def _call_registered(self):
    """Calls all registered functions"""
    logger.debug("Calling registered functions")
    while self.funcs:
        try:
            self.funcs[-1]()
        except Exception:  # pylint: disable=broad-except
            logger.error("Encountered exception during recovery: ", exc_info=True)
        self.funcs.pop()


# Traceback (certbot.errors.MisconfigurationError)
$ sudo certbot install --nginx --cert-name random27579.example.org
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator None, Installer nginx
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/default
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/default
Rolling back to previous server configuration...
Encountered exception during recovery:
Traceback (most recent call last):
File "/home/alex/devel/certbot/certbot/certbot/_internal/client.py", line 530, in deploy_certificate
self.installer.restart()
File "/home/alex/devel/certbot/certbot-nginx/certbot_nginx/_internal/configurator.py", line 918, in restart
nginx_restart(self.conf('ctl'), self.nginx_conf, self.conf('sleep-seconds'))
File "/home/alex/devel/certbot/certbot-nginx/certbot_nginx/_internal/configurator.py", line 1199, in nginx_restart
raise errors.MisconfigurationError(
certbot.errors.MisconfigurationError: nginx restart failed:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/alex/devel/certbot/certbot/certbot/_internal/error_handler.py", line 125, in _call_registered
self.funcs[-1]()
File "/home/alex/devel/certbot/certbot/certbot/_internal/client.py", line 630, in _rollback_and_restart
self.installer.restart()
File "/home/alex/devel/certbot/certbot-nginx/certbot_nginx/_internal/configurator.py", line 918, in restart
nginx_restart(self.conf('ctl'), self.nginx_conf, self.conf('sleep-seconds'))
File "/home/alex/devel/certbot/certbot-nginx/certbot_nginx/_internal/configurator.py", line 1199, in nginx_restart
raise errors.MisconfigurationError(
certbot.errors.MisconfigurationError: nginx restart failed:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

nginx restart failed:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()


IMPORTANT NOTES:
- An error occurred and we failed to restore your config and restart
your server. Please post to
https://community.letsencrypt.org/c/help with details about your
configuration and this error you received.

# Fixed code
def _call_registered(self):
    """Calls all registered functions"""
    logger.debug("Calling registered functions")
    while self.funcs:
        try:
            self.funcs[-1]()
        except Exception as exc:  # pylint: disable=broad-except
            output = traceback.format_exception_only(type(exc), exc)
            logger.error(
                "Encountered exception during recovery: %s", "".join(output).rstrip()
            )
        self.funcs.pop()