-
Notifications
You must be signed in to change notification settings - Fork 474
async ChatHandler exceeds aiohttp.ProxyConnector limit #103
Comments
Rummaged through the
Looks like configuring the connector to keep connections works:
Meanwhile:
Looks like when |
@aderbenev, thanks for laying out the whole story. Fixing the underlying HTTP library's keep-alive issues is my next priority, both for |
I have overcome the issue described by setting the While troubleshooting the related connectivity issues for aiohttp, I stumbled upon reconnect problem on network failure described here. The way it affected telepot for me, in request function I had to add some handling for
That is, on timeout I explicitly close all connections and later construct a new ProxyConnector object in |
@aderbenev, first I want to thank you for all the troubleshooting. It exposes a bunch of issues I have not considered. Before I go any further, I want to be certain about the necessity of your fix (on timeout, explicitly closing all connections and later construct a new ProxyConnector to avoid sporadic connectivity issues break the connector irreversibly). Is this fix only needed for ProxyConnector, or all types of connectors? Your comments make me think that maybe I have assumed too much intelligence in |
@nickoala, sadly I can't provide a comprehensive suite for other scenarios (e.g. different connectors) since my setup is running behind the proxy I cannot bypass. That is, using another connector would not let the bot to connect at all. Also, I don't know at which point the connection is broken in my case, and recreating this particular issue deliberately is not simple. Alas, judging by the scary exception trace my best bet was to assume that if the connection is terminated prematurely, the connector becomes broken for good. |
@aderbenev, thank you. Before telepot, I have not used any library's connection pooling facilities. But when I think about connection pooling, I envision these functionalities (and assume any libraries that support connection pooling to have them): It creates/re-uses/fixes connections as needed, transparently, within the connection limit. If a connection is idle for some (specified) time, it is closed. If a connection is broken, a new connection is tried.As a user, all I care about is making HTTP requests efficiently. I don't want to manage connections. Apparently, it is not as ideal as I imagine. Your situation has another dimension: Is it only a property of Given the unstability after implementing connection pooling (on both I don't want to be bogged down by these issues, while having other improvements to make. Basically, I just want to move on. Callback query handling is yet to complete. I want to move on and complete that first ..... |
After configuring a proxy as described in #85, using the async DelegatorBot skeleton resulted in an issue. Given the proxy connector limit configuration of 10:
the bot only answers 5 requests and then becomes stuck throwing exceptions on some internal timeout. To test the issue, I was sending a message and allowed ChatHandler to expire before sending another one. I also added some printout to see what's happening:
After answering to five messages and when the next one is supposed to be received from the client, nothing happens on the bot side for some time (approx. 48 seconds), and then exceptions pop up:
Then, those two tracebacks keep appearing on the same timeout while no messages are processed and no Counter methods are called. The issue also persists even if I don't wait for ChatHandler object timeout to expire.
Since I had some faith in the skeleton code, I opted to play some with configuration of my proxy connectors:
It seems that removing the limit on ProxyConnector (default behavior) fixes the issue. Although it looks like a working practical solution, the original problem investigation shows that even though ChatHandler on_close is called (and the object is presumably deleted), this does not close the corresponding ProxyConnector connection(s). Even when only one ChatHandler is created, five calls to
on_chat_message
exhaust the ProxyConnectorlimit=10
, which probably indicates that ProxyConnector connections are not closed nor reused every time messages are received or sent.Also, making the bot not send anything in return (by commenting out
yield from self.sender.sendMessage(self._count)
inon_chat_message
method) allows the bot to receive 10 messages. It means that one ProxyConnector connection is needed for the bot for each receive or send operation, and because of that with the original skeleton version the limit is 10/2 = 5 messages before the issue occurs.I don't know much about internal logic of the bot connection handling, but I'd assume that connections should be either closed or reused. For now, any ProxyConnector connection limit (except
None
) will be eventually exhausted, causing the bot to stuck.The text was updated successfully, but these errors were encountered: