telegram-bot-api icon indicating copy to clipboard operation
telegram-bot-api copied to clipboard

not able to set more webhooks!

Open abdoo9 opened this issue 1 year ago • 9 comments

I've setWebhook for 1789 bots and start getting these errors and not able to set more webhooks!

{
  ok: false,
  error_code: 400,
  description: 'Bad Request: bad webhook: Failed to create a socket'
}
{
  ok: false,
  error_code: 500,
  description: 'Internal Server Error: restart'
}

abdoo9 avatar Jun 17 '24 21:06 abdoo9

The number of file descriptors allowed by your operating system per process has been exceeded. You can use ulimit or --max-connections option if the process is launched with enough priviledges to increase it.

levlam avatar Jun 18 '24 12:06 levlam

@levlam yes that's correct when I upgrade my vps I was able to set more webhooks but the problem is that I don't afford such a big server also it seems like the VPS provider seems to be setting a limit for file descriptors when I used the --max-connections flag I'm getting this error

Can't set file descriptor limit: Failed to set resource limit

I don't have a lot of experience with these stuff is there a way to run the bot-api without it creating a folder for each bot? like could it use some sort of database with sacrificing some features

abdoo9 avatar Jun 18 '24 18:06 abdoo9

Server size doesn't matter at all. Those are settings of the operating system.

You need corresponding priviledges to use --max-connections. The simplest way is to run the Bot API server from root user and pass also options --username and --groupname to allow the server to drop unneeded privileges.

Alternatively, you can use ulimit from root user yourself to change the limit for all processes.

levlam avatar Jun 18 '24 20:06 levlam

I've increased the file handlers and now the Bot API is eating my ram Screenshot 2024-06-19 at 03 12 38

abdoo9 avatar Jun 19 '24 00:06 abdoo9

The number of allowed file descriptors doesn't affect RAM usage. Likely. you have some highloaded bots with big amount of updates per second.

levlam avatar Jun 19 '24 00:06 levlam

ok now when I run it, it works fine for a while then it crashes the logs file is big this is the tail of it

./telegram-bot-api(+0x11dccd9)[0x55ffc2995cd9]
./telegram-bot-api(+0x170279)[0x55ffc1929279]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f895cabd520]
./telegram-bot-api(+0xe928e0)[0x55ffc264b8e0]
./telegram-bot-api(+0xdf1e82)[0x55ffc25aae82]
./telegram-bot-api(+0xdf5b4c)[0x55ffc25aeb4c]
./telegram-bot-api(+0xdf9275)[0x55ffc25b2275]
./telegram-bot-api(+0xe04f14)[0x55ffc25bdf14]
./telegram-bot-api(+0xe04ce0)[0x55ffc25bdce0]
./telegram-bot-api(+0xe04c07)[0x55ffc25bdc07]
./telegram-bot-api(+0xe046b2)[0x55ffc25bd6b2]
./telegram-bot-api(+0x13c2acc)[0x55ffc2b7bacc]
./telegram-bot-api(+0x13c28cf)[0x55ffc2b7b8cf]
./telegram-bot-api(+0x2c26dd)[0x55ffc1a7b6dd]
./telegram-bot-api(+0x2c42a2)[0x55ffc1a7d2a2]
./telegram-bot-api(+0x2c449f)[0x55ffc1a7d49f]
./telegram-bot-api(+0x2c4858)[0x55ffc1a7d858]
./telegram-bot-api(+0x2c48b3)[0x55ffc1a7d8b3]
./telegram-bot-api(+0x2bf0ff)[0x55ffc1a780ff]
./telegram-bot-api(+0x16e90a)[0x55ffc192790a]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f895caa4d90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f895caa4e40]
./telegram-bot-api(+0x16bb95)[0x55ffc1924b95]
-------------------------------
[pid 56063] [time 1718806793] 6945168719
------- Stack Backtrace -------
./telegram-bot-api(+0x11dccd9)[0x55ffc2995cd9]
./telegram-bot-api(+0x170279)[0x55ffc1929279]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f895cabd520]
./telegram-bot-api(+0xe928e0)[0x55ffc264b8e0]
./telegram-bot-api(+0xdf1e82)[0x55ffc25aae82]
./telegram-bot-api(+0xdf5b4c)[0x55ffc25aeb4c]
./telegram-bot-api(+0xdf9275)[0x55ffc25b2275]
./telegram-bot-api(+0xe04f14)[0x55ffc25bdf14]
./telegram-bot-api(+0xe04ce0)[0x55ffc25bdce0]
./telegram-bot-api(+0xe04c07)[0x55ffc25bdc07]
./telegram-bot-api(+0xe046b2)[0x55ffc25bd6b2]
./telegram-bot-api(+0x13c2acc)[0x55ffc2b7bacc]
./telegram-bot-api(+0x13c28cf)[0x55ffc2b7b8cf]
./telegram-bot-api(+0x2c26dd)[0x55ffc1a7b6dd]
./telegram-bot-api(+0x2c42a2)[0x55ffc1a7d2a2]
./telegram-bot-api(+0x2c449f)[0x55ffc1a7d49f]
./telegram-bot-api(+0x2c4858)[0x55ffc1a7d858]
./telegram-bot-api(+0x2c48b3)[0x55ffc1a7d8b3]
./telegram-bot-api(+0x2bf0ff)[0x55ffc1a780ff]
./telegram-bot-api(+0x16e90a)[0x55ffc192790a]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f895caa4d90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f895caa4e40]
./telegram-bot-api(+0x16bb95)[0x55ffc1924b95]
-------------------------------
[pid 56063] [time 1718806794] 6945168719

abdoo9 avatar Jun 19 '24 15:06 abdoo9

Those aren't crashes.

Also, you seems to use an old Bot API server version.

levlam avatar Jun 19 '24 15:06 levlam

I'm running 7.4 are you sure the Bot API can withstand 100K bots with high load? I think the bot-api is spawning multiple processes and they are fighting on webhooks_db.binlog this is what I understand from the logs not sure about that. this is the signal of the crash

------- Stack Backtrace -------
./telegram-bot-api(+0x11dccd9)[0x561cf5456cd9]
./telegram-bot-api(+0x170279)[0x561cf43ea279]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7fad197c4520]
./telegram-bot-api(+0x2c4c75)[0x561cf453ec75]
./telegram-bot-api(+0x2c4606)[0x561cf453e606]
./telegram-bot-api(+0x2c4860)[0x561cf453e860]
./telegram-bot-api(+0x2c4950)[0x561cf453e950]
./telegram-bot-api(+0x2bf0ff)[0x561cf45390ff]
./telegram-bot-api(+0x16e90a)[0x561cf43e890a]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7fad197abd90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7fad197abe40]
./telegram-bot-api(+0x16bb95)[0x561cf43e5b95]
-------------------------------
[ 0][t 6][1718813064.056725025][ClientManager.cpp:353][!ClientManager][&status.is_error()]	Can't open webhooks_db.binlog [PosixError : Resource temporarily unavailable : 11 : Can't lock file "/root/telegram-bot-api/bin/webhooks_db.binlog", because it is already in use; check for another program instance running]
[pid 68941] [time 1718813064] ------- Log dump -------

LOG:00000000:  [ 2][t 1][1718813046.343164920][telegram-bot-api.cpp:460]	Bot API 7.4 server started            
LOG:00000070:  [ 2][t12][1718813046.348649024][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: UNKNOWN         
LOG:000000e0:  [ 2][t12][1718813047.335486173][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 3.120936%       
LOG:00000150:  [ 2][t12][1718813048.338251113][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 4.121056%       
LOG:000001c0:  [ 2][t12][1718813049.336096048][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 3.751865%       
LOG:00000230:  [ 2][t12][1718813050.335453033][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 3.312629%       
LOG:000002a0:  [ 2][t12][1718813051.334908962][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 3.465410%       
LOG:00000310:  [ 2][t12][1718813052.335215330][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 3.391986%       
LOG:00000380:  [ 2][t12][1718813053.334599018][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 3.485206%       
LOG:000003f0:  [ 2][t 6][1718813054.130551099][ClientManager.cpp:344][!ClientManager]	Loaded 22249 TQueue events in 7.785510 seconds           
LOG:00000480:  [ 2][t12][1718813054.335699081][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 9.263959%       
LOG:000004f0:  [ 2][t12][1718813055.335442066][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 8.690132%       
LOG:00000560:  [ 2][t12][1718813056.335437059][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 8.032537%       
LOG:000005d0:  [ 2][t12][1718813057.335407257][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 12.628899%      
LOG:00000640:  [ 2][t12][1718813058.336191177][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 11.223297%      
LOG:000006b0:  [ 2][t12][1718813059.335165977][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 10.063810%      
LOG:00000720:  [ 2][t12][1718813060.335497140][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 9.174896%       
LOG:00000790:  [ 2][t12][1718813061.336686134][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 8.484763%       
LOG:00000800:  [ 2][t12][1718813062.334946155][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 7.947020%       
LOG:00000870:  [ 2][t12][1718813063.336161136][Stats.cpp:34][!RunOnSchedulerWorker]	CPU usage: 3.399554%       
LOG:000008e0:  [ 0][t 6][1718813064.056725025][ClientManager.cpp:353][!ClientManager][&status.is_error()]	Can't open webhooks_db.binlog [PosixError : Resource temporarily unavailable : 11 : Can't lock file "/root/telegram-bot-api/bin/webhooks_db.binlog", because it is already in use; check for another program instance running]       
[pid 68941] [time 1718813064] ------------------------
[pid 68941] [time 1718813064] Signal: 6
------- Stack Backtrace -------
./telegram-bot-api(+0x11dccd9)[0x557bf457bcd9]
./telegram-bot-api(+0x17015f)[0x557bf350f15f]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f6378b55520]
/lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x7f6378ba99fc]
/lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x7f6378b55476]
/lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7f6378b3b7f3]
./telegram-bot-api(+0x1201729)[0x557bf45a0729]
./telegram-bot-api(+0x120203c)[0x557bf45a103c]
./telegram-bot-api(+0x297847)[0x557bf3636847]
./telegram-bot-api(+0x2c26b3)[0x557bf36616b3]
./telegram-bot-api(+0x2c42a2)[0x557bf36632a2]
./telegram-bot-api(+0x2c449f)[0x557bf366349f]
./telegram-bot-api(+0x2c4858)[0x557bf3663858]
./telegram-bot-api(+0x2c48b3)[0x557bf36638b3]
./telegram-bot-api(+0x2bfd46)[0x557bf365ed46]
./telegram-bot-api(+0x2bfd7e)[0x557bf365ed7e]
./telegram-bot-api(+0x2bfc90)[0x557bf365ec90]
/lib/x86_64-linux-gnu/libc.so.6(+0x94ac3)[0x7f6378ba7ac3]
/lib/x86_64-linux-gnu/libc.so.6(+0x126850)[0x7f6378c39850]
-------------------------------
[pid 72013] [time 1718814311] 5156639744

abdoo9 avatar Jun 19 '24 16:06 abdoo9

Bot API server is one process. You can't launch multiple Bot API servers in a given working directory, but you are trying to do so, and additional instances exit with the mentioned errors.

The number of bots a Bot API server can handle solely depends on the OS and server capabilities and load of the bots. At api.telegram.org a server definitely can serve more than 100000 bots.

levlam avatar Jun 19 '24 19:06 levlam