GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Handling network errors Handling network errors
Hinrich Mahler edited this page
Network errors can happen at many levels, on the local side, on the remote or somewhere along the way. It is hard for applications to identify when an error occurs as it is not always something that can be identified in real time but rather when an additional event happens. Network errors are a problem which each application have to deal with. Each application for its own use case and desired service level. For something to "break" locally we need to close the network socket. This is something that PTB doesn't do voluntarily and basically if you've encountered such a case, it's a bug. There is a suspicion that Telegram are closing connections on some conditions. Whether it is true or not we can't really tell. The application should still be able to deal with it.
There is no one way to handle networking issues. Each bot has its own usage pattern and unique network behaviour. Some bots will require providing answer to user requests within a limited time, while others can take all the time they need. Some bots will be ok with "losing" a sent message once in a while, while others must ensure that the message was sent within a limited time frame. Some bots send big files, while others only receive small files. Etc., etc. In addition, the network connection takes an important factor. Hosting your bot in a region with poor Internet (bandwidth / packet lost / disconnections) is the obvious example, but it is not the only problem. In case the bot is hosted "far" from the Telegram Bot servers you'll experience greater latency and possibly more packet loss. TCP should be able to handle packet loss, however, there are side effects for that (when will TCP identify the loss of a packet? what will be the window size? etc.). Hosting the bot on a slow server can also affect performance and may be observed as networking issues. Once you've understood the usage pattern of your bot (that includes the QoS) you can go into fine-tuning the ptb library for your needs. PTB performs HTTPS requests using the
The built-in The When using the standard Application.builder().token("Token").read_timeout(7).get_updates_read_timeout(42).build() Note that there is both See also the wiki page on the builder pattern. When using To be specific, when using the raw API (i.e. using If you're using Depending on the SLA you'd like to provide, if you suffer from frequent errors during
Depending on your OS you may be able to set socket options to perform low level tweaks.
In the default networking backend, When a network error occurs, be prepared to catch the raised exception and handle it according to your policy (do you want to retry? ignore? other?) or use PTBs built-in mechanism for exception handling. Note that for (network) errors that happen as part of If you think of another way to improve stability from within ptb, please contact us (the maintainers). Wiki of
Clone this wiki locally |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |