Repository: jina-ai/jina
File: jina/clients/base/helper.py (Python)

Code before:
class HTTPClientlet(AioHttpClientlet):
    """HTTP Client to be used with the streamer"""

    async def send_message(self, request: 'Request'):
        """Sends a POST request to the server

        :param request: request as dict
        :return: send post message
        """
        req_dict = request.to_dict()
        req_dict['exec_endpoint'] = req_dict['header']['exec_endpoint']
        if 'target_executor' in req_dict['header']:
            req_dict['target_executor'] = req_dict['header']['target_executor']
        for retry in range(self.max_attempts):
            try:
                res = await self.session.post(url=self.url, json=req_dict).__aenter__()
                return res
            except:
                if retry == self.max_attempts - 1:
                    raise
                else:
                    if retry == 0:
                        wait_time = random.uniform(0, self.initial_backoff)
                    else:
                        wait_time = random.uniform(0, min(self.initial_backoff*self.backoff_multiplier**(retry-1), self.max_backoff))
                    await asyncio.sleep(wait_time)

    async def send_dry_run(self):
        """Query the dry_run endpoint from Gateway
        :return: send get message
        """
        return await self.session.get(url=self.url).__aenter__()

    async def recv_message(self):
        """Receive message for HTTP (sleep)

        :return: await sleep
        """
        return await asyncio.sleep(1e10)

    async def recv_dry_run(self):
        """Receive dry run response for HTTP (sleep)

        :return: await sleep
        """
        return await asyncio.sleep(1e10)


class WsResponseIter:
    """
    Iterates over all the responses that come in over the websocket connection.

Review comment (suggestion):
```suggestion
        for retry in range(1, self.max_attempts + 1):
            try:
                return await self.session.post(url=self.url, json=req_dict).__aenter__()
            except:
                if retry == self.max_attempts:
                    raise
                else:
                    wait_time = random.uniform(0, min(self.initial_backoff*self.backoff_multiplier**(retry-1), self.max_backoff))
                    await asyncio.sleep(wait_time)
```
also can't we be specific about the exception to catch ? (given that we're only targetting network connection errors)

Code after:
class HTTPClientlet(AioHttpClientlet):
    """HTTP Client to be used with the streamer"""

    async def send_message(self, request: 'Request'):
        """Sends a POST request to the server

        :param request: request as dict
        :return: send post message
        """
        req_dict = request.to_dict()
        req_dict['exec_endpoint'] = req_dict['header']['exec_endpoint']
        if 'target_executor' in req_dict['header']:
            req_dict['target_executor'] = req_dict['header']['target_executor']
        for retry in range(1, self.max_attempts + 1):
            try:
                return await self.session.post(url=self.url, json=req_dict).__aenter__()
            except:
                if retry == self.max_attempts:
                    raise
                else:
                    wait_time = random.uniform(0, min(self.initial_backoff*self.backoff_multiplier**(retry-1), self.max_backoff))
                    await asyncio.sleep(wait_time)

    async def send_dry_run(self):
        """Query the dry_run endpoint from Gateway
        :return: send get message
        """
        return await self.session.get(url=self.url).__aenter__()

    async def recv_message(self):
        """Receive message for HTTP (sleep)

        :return: await sleep
        """
        return await asyncio.sleep(1e10)

    async def recv_dry_run(self):
        """Receive dry run response for HTTP (sleep)

        :return: await sleep
        """
        return await asyncio.sleep(1e10)


class WsResponseIter:
    """
    Iterates over all the responses that come in over the websocket connection.
    In contrast to the iterator built into AioHTTP, this also records the message that was sent at closing-time.
    """

    def __init__(self, websocket):