code: async def discover_master(self, service, timeout):
          
          # TODO: get lock
          idle_timeout = timeout
          # FIXME: single timeout used 4 times;
          #   meaning discovery can take up to:
          #   3 * timeout * (sentinels count)
          #
          #   having one global timeout also can leed to
          #   a problem when not all sentinels are checked.
  
          # use a copy, cause pools can change
          pools = self._pools[:]
          for sentinel in pools:
              try:
                  with async_timeout(timeout, loop=self._loop):
                      address = await self._get_masters_address(
                          sentinel, service)
  
                  pool = self._masters[service]
                  with async_timeout(timeout, loop=self._loop), \
                          contextlib.ExitStack() as stack:
                      conn = await pool._create_new_connection(address)
                      stack.callback(conn.close)
                      await self._verify_service_role(conn, 'master')
                      stack.pop_all()
  
                  return conn
              except asyncio.CancelledError:
                  # we must correctly handle CancelledError(s):
                  #   application may be stopped or function can be cancelled
                  #   by outer timeout, so we must stop the look up.
                  raise
              except asyncio.TimeoutError:
                  continue
              except DiscoverError as err:
                  sentinel_logger.debug("DiscoverError(%r, %s): %r",
                                        sentinel, service, err)
                  await asyncio.sleep(idle_timeout, loop=self._loop)
                  continue
              except RedisError as err:
                  raise MasterReplyError("Service {} error".format(service), err)
              except Exception:
                  # TODO: clear (drop) connections to schedule reconnect
                  await asyncio.sleep(idle_timeout, loop=self._loop)
                  continue
          else:
              raise MasterNotFoundError("No master found for {}".format(service))
docs: Perform Master discovery for specified service.