Skip to content

Commit

Permalink
并发调用文心模型,获取token时出现异常问题修复
Browse files Browse the repository at this point in the history
第一个请求获取到BaiduAccessToken对象就释放了锁,此时对象中的access_token还是空。第二个请求马上进来直接拿走这个对象,导致获取到的access_token为空,进而导致请求模型报错
  • Loading branch information
puqs1 committed Sep 4, 2024
1 parent 14af875 commit e1eafb4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions api/core/model_runtime/model_providers/wenxin/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ def get_access_token(api_key: str, secret_key: str) -> 'BaiduAccessToken':
# if access token not in cache, request it
token = BaiduAccessToken(api_key)
baidu_access_tokens[api_key] = token
# release it to enhance performance
# btw, _get_access_token will raise exception if failed, release lock here to avoid deadlock
baidu_access_tokens_lock.release()
# try to get access token
token_str = BaiduAccessToken._get_access_token(api_key, secret_key)
try:
# try to get access token
token_str = BaiduAccessToken._get_access_token(api_key, secret_key)
finally:
# release it to enhance performance
# btw, _get_access_token will raise exception if failed, release lock here to avoid deadlock
baidu_access_tokens_lock.release()
token.access_token = token_str
token.expires = now + timedelta(days=3)
return token
Expand Down

0 comments on commit e1eafb4

Please sign in to comment.