Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling request - Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7face6e61d68> Unclosed connector connections: .... #3

Open
igorwebb opened this issue Oct 9, 2019 · 1 comment

Comments

@igorwebb
Copy link

igorwebb commented Oct 9, 2019

Hi, my docker server is working fine. But when I make a lot of requests using aiohttp from my python application, the server responds with a 504 error and writes to the log:

Error handling request
Error handling request
Error handling request
^C======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7face6e61d68>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7facde557388>, 5138.691)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde68eb40>, 4843.989)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde557c10>, 5124.785)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde68ea08>, 5135.462)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facf7ed0800>, 5124.289)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52ece0>, 5130.191)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde557590>, 5137.217)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde5cf6c8>, 5128.721)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde59ca08>, 5119.731)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52e0b0>, 5112.963), (<aiohttp.client_proto.ResponseHandler object at 0x7facde512c10>, 5113.93)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52ef50>, 5133.297)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde7999a0>, 5136.193)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7face40f4ad8>, 5137.71)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde5574c0>, 5129.21)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde878250>, 4843.473)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52e800>, 5107.494), (<aiohttp.client_proto.ResponseHandler object at 0x7facde52ea70>, 5107.516), (<aiohttp.client_proto.ResponseHandler object at 0x7facde52e590>, 5111.026), (<aiohttp.client_proto.ResponseHandler object at 0x7facde52eba8>, 5136.718)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde5cf5f8>, 5119.217), (<aiohttp.client_proto.ResponseHandler object at 0x7facde6f5048>, 5126.76)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52ea08>, 5121.286)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7face409d6c8>, 5130.681)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde5570b0>, 5126.269)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde512d48>, 5122.311)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52cb40>, 5120.225)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde557528>, 5134.891)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7face48152b8>, 5108.08)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde512730>, 5107.541), (<aiohttp.client_proto.ResponseHandler object at 0x7facde52c798>, 5133.84)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde504320>, 5138.2)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52e528>, 5120.744)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7face4815d48>, 5134.35)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52cdb0>, 5107.515), (<aiohttp.client_proto.ResponseHandler object at 0x7facde52c660>, 5108.589), (<aiohttp.client_proto.ResponseHandler object at 0x7facde7d52b8>, 5123.794)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde52e6c8>, 5125.281)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7facde59c798>, 5118.149)]']
connector: <aiohttp.connector.TCPConnector object at 0x7face6e61dd8>

My program code:

async def call_url(att, session, images):
	if "attachment" in att:
		print('Starting {}'.format(att["photo"]))
		await asyncio.sleep(1)
		while True:
			try:
				async with session.post(
						"http://192.168.1.70:8080",
						data={"url": att["photo"]},
				) as response:
					print(response.status)
					text = await response.text()
					print(str(text))
					print("\n")
			except asyncio.TimeoutError:
				print('Timeout Error: ' + att["photo"] + "\n")
				await asyncio.sleep(1)
				continue
			else:
				break
		else:
			images.append(att["photo"], False)
			return images.jsonPhotos

async def run(history, images):
	async with aiohttp.ClientSession() as session:
		futures = [call_url(mess, session, images) for mess in history]
		result = await asyncio.gather(*futures)
		return result
		
ioloop = asyncio.new_event_loop()
asyncio.set_event_loop(ioloop)

ioloop.run_until_complete(run(items, images))

ioloop.close()
@igorwebb
Copy link
Author

igorwebb commented Oct 9, 2019

Google think u need close your session = aiohttp.ClientSession():

import aiohttp
session = aiohttp.ClientSession()
#use the session here
session.close()

in api.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant