fix lib exception to asyncio TimeoutError
This commit is contained in:
parent
c2e7b5a67d
commit
20a5aecfca
2 changed files with 4 additions and 3 deletions
|
@ -8,6 +8,7 @@ from operator import itemgetter
|
||||||
from typing import Optional, List, Iterable
|
from typing import Optional, List, Iterable
|
||||||
|
|
||||||
from elasticsearch import AsyncElasticsearch, NotFoundError, ConnectionError
|
from elasticsearch import AsyncElasticsearch, NotFoundError, ConnectionError
|
||||||
|
from elasticsearch.exceptions import ConnectionTimeout
|
||||||
from elasticsearch.helpers import async_streaming_bulk
|
from elasticsearch.helpers import async_streaming_bulk
|
||||||
|
|
||||||
from lbry.crypto.base58 import Base58
|
from lbry.crypto.base58 import Base58
|
||||||
|
@ -228,6 +229,8 @@ class SearchIndex:
|
||||||
expand_query(**kwargs), index=self.index, track_total_hits=200
|
expand_query(**kwargs), index=self.index, track_total_hits=200
|
||||||
)
|
)
|
||||||
cache_item.result = zlib.compress(json.dumps(result).encode(), 1)
|
cache_item.result = zlib.compress(json.dumps(result).encode(), 1)
|
||||||
|
except ConnectionTimeout:
|
||||||
|
raise TimeoutError()
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
# index has no docs, fixme: log something
|
# index has no docs, fixme: log something
|
||||||
return [], 0, 0
|
return [], 0, 0
|
||||||
|
|
|
@ -1009,9 +1009,7 @@ class LBRYElectrumX(SessionBase):
|
||||||
try:
|
try:
|
||||||
self.session_mgr.pending_query_metric.inc()
|
self.session_mgr.pending_query_metric.inc()
|
||||||
return await self.db.search_index.session_query(query_name, kwargs)
|
return await self.db.search_index.session_query(query_name, kwargs)
|
||||||
except (TimeoutError, asyncio.TimeoutError) as error:
|
except (TimeoutError, asyncio.TimeoutError):
|
||||||
metrics = self.get_metrics_or_placeholder_for_api(query_name)
|
|
||||||
metrics.query_interrupt(start, error.metrics)
|
|
||||||
self.session_mgr.interrupt_count_metric.inc()
|
self.session_mgr.interrupt_count_metric.inc()
|
||||||
raise RPCError(JSONRPC.QUERY_TIMEOUT, 'query timed out')
|
raise RPCError(JSONRPC.QUERY_TIMEOUT, 'query timed out')
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Reference in a new issue