Skip to content

Commit

Permalink
fix http session closed error (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaodongen authored Nov 24, 2024
1 parent 644a4e8 commit 790cd08
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def on_stop(self, ten_env: AsyncTenEnv) -> None:
ten_env.log_debug("on_stop")

# TODO: clean up resources
if self.session:
if self.session and not self.session.closed:
await self.session.close()
self.session = None # Ensure it can't be reused accidentally

Expand Down Expand Up @@ -145,7 +145,13 @@ async def _do_search(self, args: dict) -> Any:

return snippets

async def _initialize_session(self):
if self.session is None or self.session.closed:
logger.debug("Initializing new session")
self.session = aiohttp.ClientSession()

async def _bing_search_results(self, search_term: str, count: int) -> List[dict]:
await self._initialize_session()
headers = {"Ocp-Apim-Subscription-Key": self.api_key}
params = {
"q": search_term,
Expand Down

0 comments on commit 790cd08

Please sign in to comment.