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
gefragt vor 4 Monaten253 Aufrufe
1 Antwort
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
EXPERTE
beantwortet vor 4 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen