redis/redis-py · error · MasterNotFoundError

No master found for

Error message

No master found for {service_name!r}{error_info}

What it means

Raised as MasterNotFoundError (a ConnectionError subclass) from Sentinel.discover_master after iterating every configured Sentinel node and finding none that can report a valid, non-ODOWN master for the given service_name. The message appends collected connection errors from each sentinel it could not reach. This is the top-level master-discovery failure for the Sentinel client.

Solutions

  1. Confirm the Sentinel addresses passed to Sentinel(...) are correct and reachable (telnet/redis-cli ping each one).
  2. Run `redis-cli -p 26379 sentinel get-master-addr-by-name <service_name>` to confirm Sentinel knows the master.
  3. Check that the master is not flagged ODOWN/SDOWN and that Sentinel quorum is healthy.
  4. Verify the service_name matches the monitored master name in sentinel.conf.

Example fix

# before
sentinel = Sentinel([('sentinel-host', 26379)])
master = sentinel.master_for('wrong-name')  # MasterNotFoundError
# after
sentinel = Sentinel([('sentinel-host', 26379)])
master = sentinel.master_for('mymaster')  # correct monitored name
Defensive patterns

Strategy: retry

Validate before calling

addrs = await sentinel.discover_master(service_name)  # raises MasterNotFoundError if down

Try / catch

from redis.asyncio.sentinel import MasterNotFoundError
for attempt in range(retries):
    try:
        return await sentinel.master_for(service_name).get(key)
    except MasterNotFoundError:
        await asyncio.sleep(backoff)

Prevention

When it happens

Trigger: Calling discover_master(service_name) (directly or via master_for() usage) where every sentinel either is unreachable (ConnectionError/TimeoutError, recorded in error_info) or does not return a passing master state via check_master_state.

Common situations: All Sentinel nodes are down or unreachable. The service_name does not exist in Sentinel config. Master is in ODOWN (objective down) so check_master_state rejects it. Network partition between the client and the Sentinel quorum. Wrong sentinel addresses/ports in the Sentinel() constructor.

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/65e382ad22dfdf73. Report an issue: GitHub.

Appendix: source

Thrown at redis/asyncio/sentinel.py:344

            state = masters.get(service_name)
            if state and self.check_master_state(state, service_name):
                # Put this sentinel at the top of the list
                self.sentinels[0], self.sentinels[sentinel_no] = (
                    sentinel,
                    self.sentinels[0],
                )

                ip = (
                    self._force_master_ip
                    if self._force_master_ip is not None
                    else state["ip"]
                )
                return ip, state["port"]

        error_info = ""
        if len(collected_errors) > 0:
            error_info = f" : {', '.join(collected_errors)}"
        raise MasterNotFoundError(f"No master found for {service_name!r}{error_info}")

    def filter_slaves(
        self, slaves: Iterable[Mapping]
    ) -> Sequence[Tuple[EncodableT, EncodableT]]:
        """Remove slaves that are in an ODOWN or SDOWN state"""
        slaves_alive = []
        for slave in slaves:
            if slave["is_odown"] or slave["is_sdown"]:
                continue
            slaves_alive.append((slave["ip"], slave["port"]))
        return slaves_alive

    def filter_replicas(
        self, replicas: Iterable[Mapping]
    ) -> Sequence[Tuple[EncodableT, EncodableT]]:
        """Remove replicas that are in an ODOWN or SDOWN state.

        This is an alias for :py:meth:`filter_slaves`,

View on GitHub (pinned to 6a6b581b48)