Python3 Aiohttp client throws an error: ClientConnectERROR: Cannot connect to host API.TLEGRAM.ORG:443 SSL:DEFAULT {Too many Open Files}

0

Hi,

i am running python telegram bot on a ec2 of mine and after it running for around 7days +/- it crashes with the error "Aiohttp client throws an error: ClientConnectERROR: Cannot connect to host API.TLEGRAM.ORG:443 SSL:DEFAULT {Too many Open Files}"

Using the ubuntu command: "lsof -p <pid>" i did find that the longer the bot is running the more connections to some ip exist with the status "(CLOSE_WAIT)" at the end:

python3 439272 ubuntu 10u IPv4 5226917 0t0 TCP ip-XX1-XX-X-XX.us-east-2.compute.internal:48770->1xx.xx.x.192:https (CLOSE_WAIT)  (IPs "blurred out")

I am pretty sure those connections just going to close_wait instead of closing for real are the reason it crashes.

Does anybody know what could cause these connections or better yet how i can automaticly close them ?

Louis
asked 4 months ago227 views
1 Answer
0

Hi,

Python psutil package will allow you to list open tcp connections via psutil. net_connections()

See https://psutil.readthedocs.io/en/latest/ for all details.

You then be able to close them.

Some sample code to do that at https://stackoverflow.com/questions/58161929/can-i-close-connection-established-by-different-process

Best,

Didier

profile pictureAWS
EXPERT
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions