diff --git a/tanner/emulators/rfi.py b/tanner/emulators/rfi.py index 1fa95487..f2eff4bc 100644 --- a/tanner/emulators/rfi.py +++ b/tanner/emulators/rfi.py @@ -38,14 +38,12 @@ async def download_file(self, path): else: try: - with aiohttp.ClientSession(loop=self._loop) as client: - resp = await client.get(url) - data = await resp.text() + async with aiohttp.ClientSession(loop=self._loop) as client: + async with await client.get(url) as resp: + data = await resp.text() except aiohttp.ClientError as client_error: self.logger.error('Error during downloading the rfi script %s', client_error) else: - await resp.release() - await client.close() tmp_filename = url.name + str(time.time()) file_name = hashlib.md5(tmp_filename.encode('utf-8')).hexdigest() with open(os.path.join(self.script_dir, file_name), 'bw') as rfile: @@ -79,10 +77,9 @@ async def get_rfi_result(self, path): with open(os.path.join(self.script_dir, file_name), 'br') as script: script_data = script.read() try: - with aiohttp.ClientSession(loop=self._loop) as session: - - resp = await session.post('http://127.0.0.1:8088/', data=script_data) - rfi_result = await resp.json() + async with aiohttp.ClientSession(loop=self._loop) as session: + async with session.post('http://127.0.0.1:8088/', data=script_data) as resp: + rfi_result = await resp.json() except aiohttp.ClientError as client_error: self.logger.error('Error during connection to php sandbox %s', client_error) else: diff --git a/tanner/session_manager.py b/tanner/session_manager.py index ad7aac73..8d3e613e 100644 --- a/tanner/session_manager.py +++ b/tanner/session_manager.py @@ -71,7 +71,6 @@ async def delete_old_sessions(self, redis_client): if not sess.is_expired(): continue await sess.remove_associated_db() - sess.remove_associated_db() await sess.remove_associated_env() self.sessions.remove(sess) try: