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

Code before:
                                        "maxBackoff": f"{retry_delay}s",
                                        "backoffMultiplier": 10,
                                        "retryableStatusCodes": ["UNAVAILABLE", "DEADLINE_EXCEEDED", "INTERNAL"],
                                    },
                                }]
                            })
                # NOTE: the retry feature will be enabled by default >=v1.40.0
                options.append(("grpc.enable_retries", 1))
                options.append(("grpc.service_config", service_config_json))

            async with GrpcConnectionPool.get_grpc_channel(
                f'{self.args.host}:{self.args.port}',
                options=options,
                asyncio=True,
                tls=self.args.tls,
            ) as channel:
                stub = jina_pb2_grpc.JinaRPCStub(channel)
                self.logger.debug(f'connected to {self.args.host}:{self.args.port}')

                with ProgressBar(
                    total_length=self._inputs_length, disable=not self.show_progress
                ) as p_bar:
                    try:
                        async for resp in stub.Call(
                            req_iter,
                            compression=self.compression,
                            metadata=kwargs.get('metadata', None),
                            credentials=kwargs.get('credentials', None),
                            timeout=kwargs.get('timeout', None),
                        ):
                            callback_exec(
                                response=resp,
                                on_error=on_error,
                                on_done=on_done,
                                on_always=on_always,
                                continue_on_error=continue_on_error,
                                logger=self.logger,
                            )
                            if self.show_progress:
                                p_bar.update()
                            yield resp
                    except (grpc.aio._call.AioRpcError, InternalNetworkError) as err:
                        my_code = err.code()
                        my_details = err.details()
                        msg = f'gRPC error: {my_code} {my_details}'
                        exc_from = None
                        exception = None

                        if my_code == grpc.StatusCode.UNAVAILABLE:
                            self.logger.error(
                                f'{msg}\nThe ongoing request is terminated as the server is not available or closed already.'

Review comment (bug):
Should we make the retry here? As I understand this code,it will still fail in case of a network error. Right?
So what about the case where the wifi is down for a few seconds? Will it retry?


Code after:
                                        "maxAttempts": max_attempts,
                                        "initialBackoff": f"{initial_backoff}s",
                                        "maxBackoff": f"{max_backoff}s",
                                        "backoffMultiplier": {backoff_multiplier},
                                        "retryableStatusCodes": ["UNAVAILABLE", "DEADLINE_EXCEEDED", "INTERNAL"],
                                    },
                                }]
                            })
                # NOTE: the retry feature will be enabled by default >=v1.40.0
                options.append(("grpc.enable_retries", 1))
                options.append(("grpc.service_config", service_config_json))

            async with GrpcConnectionPool.get_grpc_channel(
                f'{self.args.host}:{self.args.port}',
                options=options,
                asyncio=True,
                tls=self.args.tls,
            ) as channel:
                stub = jina_pb2_grpc.JinaRPCStub(channel)
                self.logger.debug(f'connected to {self.args.host}:{self.args.port}')

                with ProgressBar(
                    total_length=self._inputs_length, disable=not self.show_progress
                ) as p_bar:
                    try:
                        async for resp in stub.Call(
                            req_iter,
                            compression=self.compression,
                            metadata=kwargs.get('metadata', None),
                            credentials=kwargs.get('credentials', None),
                            timeout=kwargs.get('timeout', None),
                        ):
                            callback_exec(
                                response=resp,
                                on_error=on_error,
                                on_done=on_done,
                                on_always=on_always,
                                continue_on_error=continue_on_error,
                                logger=self.logger,
                            )
                            if self.show_progress:
                                p_bar.update()
                            yield resp
                    except (grpc.aio._call.AioRpcError, InternalNetworkError) as err:
                        my_code = err.code()
                        my_details = err.details()
                        msg = f'gRPC error: {my_code} {my_details}'

                        if my_code == grpc.StatusCode.UNAVAILABLE:
                            self.logger.error(
                                f'{msg}\nThe ongoing request is terminated as the server is not available or closed already.'