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
已提問 4 個月前檢視次數 250 次
1 個回答
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
專家
已回答 4 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南