mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-01-13 13:50:10 +08:00
添加HTTP请求超时
This commit is contained in:
parent
4601ee328c
commit
77d0277d4e
@ -32,7 +32,7 @@ class Command(enum.IntEnum):
|
||||
UPDATE_TRANSLATION = 7
|
||||
|
||||
|
||||
_http_session = aiohttp.ClientSession()
|
||||
_http_session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10))
|
||||
|
||||
room_manager: Optional['RoomManager'] = None
|
||||
|
||||
@ -576,7 +576,7 @@ class RoomInfoHandler(api.base.ApiHandler):
|
||||
res.status, res.reason)
|
||||
return room_id, 0
|
||||
data = await res.json()
|
||||
except aiohttp.ClientConnectionError:
|
||||
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
|
||||
logger.exception('room %d _get_room_info failed', room_id)
|
||||
return room_id, 0
|
||||
|
||||
@ -600,7 +600,7 @@ class RoomInfoHandler(api.base.ApiHandler):
|
||||
# res.status, res.reason)
|
||||
# return cls._host_server_list_cache
|
||||
# data = await res.json()
|
||||
# except aiohttp.ClientConnectionError:
|
||||
# except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
|
||||
# logger.exception('room %d _get_server_host_list failed', room_id)
|
||||
# return cls._host_server_list_cache
|
||||
#
|
||||
|
2
blivedm
2
blivedm
@ -1 +1 @@
|
||||
Subproject commit 13712f89ebb13b9ff9a2cf50c9d6922200538113
|
||||
Subproject commit 4669b2c1c9a1654db340d02ff16c9f88be661d9f
|
@ -146,7 +146,11 @@ export default class ChatClientDirect {
|
||||
onReceiveTimeout() {
|
||||
window.console.warn('接收消息超时')
|
||||
this.receiveTimeoutTimerId = null
|
||||
|
||||
// 直接丢弃阻塞的websocket,不等onclose回调了
|
||||
this.websocket.onopen = this.websocket.onclose = this.websocket.onmessage = null
|
||||
this.websocket.close()
|
||||
this.onWsClose()
|
||||
}
|
||||
|
||||
onWsClose () {
|
||||
|
@ -24,6 +24,7 @@ if (process.env.NODE_ENV === 'development') {
|
||||
// 开发时使用localhost:12450
|
||||
axios.defaults.baseURL = 'http://localhost:12450'
|
||||
}
|
||||
axios.defaults.timeout = 10 * 1000
|
||||
|
||||
Vue.use(VueRouter)
|
||||
Vue.use(VueI18n)
|
||||
|
@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
|
||||
DEFAULT_AVATAR_URL = '//static.hdslb.com/images/member/noface.gif'
|
||||
|
||||
_main_event_loop = asyncio.get_event_loop()
|
||||
_http_session = aiohttp.ClientSession()
|
||||
_http_session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10))
|
||||
# user_id -> avatar_url
|
||||
_avatar_url_cache: Dict[int, str] = {}
|
||||
# 正在获取头像的Future,user_id -> Future
|
||||
|
@ -21,7 +21,7 @@ NO_TRANSLATE_TEXTS = {
|
||||
}
|
||||
|
||||
_main_event_loop = asyncio.get_event_loop()
|
||||
_http_session = aiohttp.ClientSession()
|
||||
_http_session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10))
|
||||
_translate_providers: List['TranslateProvider'] = []
|
||||
# text -> res
|
||||
_translate_cache: Dict[str, str] = {}
|
||||
@ -127,7 +127,6 @@ class TencentTranslate(TranslateProvider):
|
||||
self._reinit_future = None
|
||||
# 连续失败的次数
|
||||
self._fail_count = 0
|
||||
self._cool_down_future = None
|
||||
|
||||
async def init(self):
|
||||
self._reinit_future = asyncio.ensure_future(self._reinit_coroutine())
|
||||
@ -174,14 +173,13 @@ class TencentTranslate(TranslateProvider):
|
||||
try:
|
||||
while True:
|
||||
await asyncio.sleep(30)
|
||||
while True:
|
||||
logger.debug('TencentTranslate reinit')
|
||||
try:
|
||||
if await self._do_init():
|
||||
break
|
||||
except Exception:
|
||||
logger.exception('TencentTranslate init error:')
|
||||
await asyncio.sleep(3 * 60)
|
||||
logger.debug('TencentTranslate reinit')
|
||||
try:
|
||||
await self._do_init()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
logger.exception('TencentTranslate init error:')
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
@ -238,26 +236,14 @@ class TencentTranslate(TranslateProvider):
|
||||
|
||||
def _on_fail(self):
|
||||
self._fail_count += 1
|
||||
# 目前没有测试出被ban的情况,为了可靠性,连续失败20次时冷却并重新init
|
||||
if self._fail_count >= 20 and self._cool_down_future is None:
|
||||
self._cool_down_future = asyncio.ensure_future(self._cool_down())
|
||||
# 目前没有测试出被ban的情况,为了可靠性,连续失败20次时冷却直到下次重新init
|
||||
if self._fail_count >= 20:
|
||||
self._cool_down()
|
||||
|
||||
async def _cool_down(self):
|
||||
def _cool_down(self):
|
||||
logger.info('TencentTranslate is cooling down')
|
||||
self._qtv = self._qtk = ''
|
||||
try:
|
||||
while True:
|
||||
await asyncio.sleep(3 * 60)
|
||||
logger.info('TencentTranslate reinit')
|
||||
try:
|
||||
if await self._do_init():
|
||||
self._fail_count = 0
|
||||
break
|
||||
except Exception:
|
||||
logger.exception('TencentTranslate init error:')
|
||||
finally:
|
||||
logger.info('TencentTranslate finished cooling down')
|
||||
self._cool_down_future = None
|
||||
self._fail_count = 0
|
||||
|
||||
|
||||
class YoudaoTranslate(TranslateProvider):
|
||||
|
@ -1,3 +1,3 @@
|
||||
aiohttp==3.5.4
|
||||
aiohttp==3.7.4
|
||||
sqlalchemy==1.3.13
|
||||
tornado==6.0.2
|
||||
|
@ -13,7 +13,7 @@ def check_update():
|
||||
|
||||
async def _do_check_update():
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10)) as session:
|
||||
async with session.get('https://api.github.com/repos/xfgryujk/blivechat/releases/latest') as r:
|
||||
data = await r.json()
|
||||
if data['name'] != VERSION:
|
||||
|
Loading…
Reference in New Issue
Block a user