telegramdesktop / tdesktop

Telegram Desktop messaging app
https://desktop.telegram.org/
Other
26.4k stars 5.25k forks source link

Too many connections to http://ip:80/api by second #28453

Open Barsovski opened 2 months ago

Barsovski commented 2 months ago

Steps to reproduce

  1. Download Telegram Desktop from official site
  2. Run app on Ubuntu
  3. Trace packages

Screenshot from 2024-09-23 13-02-57

Expected behaviour

Not so many requests by second. Why HTTP?

Actual behaviour

More than 10 POST requests by second to next servers:

My proxy server starts blocking all of my connections from time to time due to this behavior

Operating system

Ubuntu 24.04.1 LTS, GNOME Shell 46.0

Version of Telegram Desktop

5.5.5, 5.5.6 Beta

Installation source

Static binary from official website

Crash ID

No response

Logs

No response

FeeeeK commented 2 weeks ago

Looks like it's a mtproto connection, but why over http and not https?

https://github.com/telegramdesktop/tdesktop/blob/8fd9ae4e591f865c02571dc3e3093e02bd96025a/Telegram/SourceFiles/mtproto/connection_http.cpp#L33-L52

image

john-preston commented 2 weeks ago

@FeeeeK No need for TLS encryption because it uses the same MTProto encryption as in TCP connections, just using HTTP wrapped transport.

FeeeeK commented 2 weeks ago

Is there any reason why the latest version of tdesktop prefers this connection over other options?

john-preston commented 2 weeks ago

@FeeeeK It doesn't. It tries both, TCP and HTTP, to all the known endpoints, and the one which is faster is selected, others are dropped. That was working this way in all versions.

reallyuniquename commented 2 weeks ago

Why does it need so many individual connections per second? Even real HTTP does not do this.

FeeeeK commented 1 week ago

Why does it need so many individual connections per second? Even real HTTP does not do this.

@reallyuniquename wdym by "real http"? Every request in logs represents new mtproto api request and tdesktop makes a lot of them.

Also, now when the reason behind these http requests has been explained, the number of them should not be a surprise and this issue can be closed

luizluca commented 1 week ago

Why does it need so many individual connections per second? Even real HTTP does not do this.

@reallyuniquename wdym by "real http"? Every request in logs represents new mtproto api request and tdesktop makes a lot of them.

Also, now when the reason behind these http requests has been explained, the number of them should not be a surprise and this issue can be closed

Not really. The amount of connection might matter by itself. For a proxy server, it is a significant log spammer.

We need a way to make it quieter, like forcing persistent connection while using http proxy

reallyuniquename commented 1 week ago

@FeeeeK As in real HTTP clients. For example while you may see dozens of GET and POST requests in your browser network log it all goes through a single TCP or QUIC connection to the target server. I believe that's not the case for Telegram.

now when the reason behind these http requests has been explained

It really hasn't. Why does it need to hammer that endpoint so much?