-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrying on known Semantic Scholar flaky SSL error in `get_s2_doc_det…
…ails_from_doi` (#522)
- Loading branch information
1 parent
05d2650
commit e2627b4
Showing
3 changed files
with
27 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
) | ||
|
||
from .client_models import DOIOrTitleBasedProvider, DOIQuery, TitleAuthorQuery | ||
from .exceptions import DOINotFoundError | ||
from .exceptions import DOINotFoundError, make_flaky_ssl_error_predicate | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -132,16 +132,8 @@ def get_crossref_mailto() -> str: | |
return "[email protected]" | ||
|
||
|
||
def is_flaky_crossref_ssl_error(exc: BaseException) -> bool: | ||
"""Get if we should retry upon known flaky Crossref failures.""" | ||
# > aiohttp.client_exceptions.ClientConnectorError: | ||
# > Cannot connect to host api.crossref.org:443 ssl:default [nodename nor servname provided, or not known] | ||
# SEE: https://github.com/aio-libs/aiohttp/blob/v3.10.5/aiohttp/client_exceptions.py#L193-L196 | ||
return isinstance(exc, aiohttp.ClientConnectorError) and exc.host == CROSSREF_HOST | ||
|
||
|
||
@retry( | ||
retry=retry_if_exception(is_flaky_crossref_ssl_error), | ||
retry=retry_if_exception(make_flaky_ssl_error_predicate(CROSSREF_HOST)), | ||
before_sleep=before_sleep_log(logger, logging.WARNING), | ||
stop=stop_after_attempt(3), | ||
) | ||
|
@@ -273,7 +265,7 @@ async def parse_crossref_to_doc_details( | |
|
||
|
||
@retry( | ||
retry=retry_if_exception(is_flaky_crossref_ssl_error), | ||
retry=retry_if_exception(make_flaky_ssl_error_predicate(CROSSREF_HOST)), | ||
before_sleep=before_sleep_log(logger, logging.WARNING), | ||
stop=stop_after_attempt(3), | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
from collections.abc import Callable | ||
|
||
import aiohttp | ||
|
||
|
||
class DOINotFoundError(Exception): | ||
def __init__(self, message="DOI not found") -> None: | ||
self.message = message | ||
super().__init__(self.message) | ||
|
||
|
||
def make_flaky_ssl_error_predicate(host: str) -> Callable[[BaseException], bool]: | ||
def predicate(exc: BaseException) -> bool: | ||
# > aiohttp.client_exceptions.ClientConnectorError: | ||
# > Cannot connect to host api.host.org:443 ssl:default [nodename nor servname provided, or not known] | ||
# SEE: https://github.com/aio-libs/aiohttp/blob/v3.10.5/aiohttp/client_exceptions.py#L193-L196 | ||
return isinstance(exc, aiohttp.ClientConnectorError) and exc.host == host | ||
|
||
return predicate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters