diff --git a/lib/charms/mongodb/v1/mongodb_provider.py b/lib/charms/mongodb/v1/mongodb_provider.py index ad8c71705..2fc78b252 100644 --- a/lib/charms/mongodb/v1/mongodb_provider.py +++ b/lib/charms/mongodb/v1/mongodb_provider.py @@ -31,7 +31,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 12 +LIBPATCH = 13 logger = logging.getLogger(__name__) REL_NAME = "database" @@ -49,6 +49,10 @@ deleted — key that were deleted.""" +class FailedToGetHostsError(Exception): + """Raised when charm fails to retrieve hosts.""" + + class MongoDBProvider(Object): """In this class, we manage client database relations.""" @@ -145,7 +149,11 @@ def _on_relation_event(self, event): try: self.oversee_users(departed_relation_id, event) - except PyMongoError as e: + except (PyMongoError, FailedToGetHostsError) as e: + # Failed to get hosts error is unique to mongos-k8s charm. In other charms we do not + # foresee issues to retrieve hosts. However in external mongos-k8s, the leader can + # attempt to retrieve hosts while non-leader units are still enabling node port + # resulting in an exception. logger.error("Deferring _on_relation_event since: error=%r", e) event.defer() return