ckolivas
ckolivas

Reputation: 128

Does listen() backlog affect established TCP connections?

Would it be naive to create a TCP socket with a listen backlog set to minimum as a way of rate limiting new incoming connections? The server workload in question doesn't expect many new connections at any time but spends a lot of time servicing long open persistent connections. It appears that new incoming connections shouldn't affect established connections, though I've been unable to find any definitive answer in any text. Is it possible for failed new incoming connections to create some kind of TCP traffic congestion on the server with the packets it's receiving or are they dropped fast enough that it has no effect on any buffers or other part of the network stack?

Specifically the platform in use is Linux, and although it may be handled differently in different OSs, I expect them to all behave roughly the same.

EDIT What I mean by the "same" is that backlog doesn't affect established connections, though I do understand Linux discards them while Windows sends a reset.

Upvotes: 0

Views: 2233

Answers (2)

user207421
user207421

Reputation: 311018

Does listen() backlog affect established TCP connections?

It affects established connections that the server hasn't accepted yet via accept(), only in the sense that it limits the number of such connections that can exist.

Would it be naive to create a TCP socket with a listen backlog set to minimum as a way of rate limiting new incoming connections?

All it would accomplish would be to unnecessarily fail some connecting clients. They won't get any service until your server gets around to it anyway, and once the backlog queue fills they are rate-limited by your service code anyway. There is no particular reason why shortening the queue would have any beneficial effect. The other problem with the idea is that it isn't readily possible to determine what the minimum actually is, or whether you succeeded in setting it as the backlog queue length.

It appears that new incoming connections shouldn't affect established connections, though I've been unable to find any definitive answer in any text.

That is correct. There is no reason why it should affect them: that's why you won't find it written down anywhere, any more than the fact that the phase of the moon doesn't affect it either.

Is it possible for failed new incoming connections to create some kind of TCP traffic congestion on the server with the packets it's receiving

No.

or are they dropped fast enough that it has no effect on any buffers or other part of the network stack?

They're not dropped. They simply aren't even created if they won't fit on the backlog queue. Ergo their resource consumption at the server is zero.

Specifically the platform in use is Linux, and although it may be handled differently in different OSs, I expect them to all behave roughly the same.

They don't. On Windows, an incoming connection when the backlog queue is full causes an RST to be issued. On other platforms it is simply ignored.

Upvotes: 4

Philip Stuyck
Philip Stuyck

Reputation: 7467

What you describe are several types of attacks like flooding, syn attacks and other goodies resulting in denial of service.

This topic is not easy, because protection has to be implemented in all the layers, including TCP. For instance a SYN attack, fiddling with the sequence numbers, ... . At that point the packet in question already came a long way, through the ethernet layer and ip layer, bottom line it is taking resources. So if your system is under attack, the attacking packets are in your data stream just like the good ones are. The faster you can detect a packet is faulty and drop it, the better. Usually a system that is under attack will be slower. Well at least the systems that I have worked with.

Some attacks try to bring your system in a faulty state permanently, this by exploiting bugs. For instance TCP has a receive queue, if packets are constantly arriving out of order they will be stored in that receive queue. If the missing packet never arrives, then this receive queue could keep on growing and growing. Without the proper defense , this would lead to the system going completely out of resources.

There are specialised tools (codenumicon for instance) to check the vulnerability of a TCP stack implementation. You can assume that the one on linux has been properly tested using similar tools.

An attack can also occur on the application layer. If you have a TCP server and it allows only a limited amount of sessions. A malicious user can simply take all the connections simply by establishing all the connections and then not doing anything with it. So you have to create some defense as well. Weather or not you set this limit very low or high does not change a thing. A malicious user will try anything to bring your system down. You need to built in defense anyway. You can connect to a webserver (HTTP) simply using telnet. If you don't send anything the server's defense will come into play and close the connection.

So bringing the amount of possible connections to a low value and thinking that this in itself is a form of protection is indeed naive.

Is it possible for failed new incoming connections to create some kind of TCP traffic congestion on the server with the packets it's receiving or are they dropped fast enough that it has no effect on any buffers or other part of the network stack?

They are using resources of your machine and will make your system run slower.

It appears that new incoming connections shouldn't affect established connections, though I've been unable to find any definitive answer in any text.

If it is normal user trying to establish a connection, even if he is doing it continuously, retrying upon failure. The influence will be minimal, close to nothing. But a malicious user that is flooding connections attempts will have influence on the system performance, because the system has to spent time identifying those flawed packets and dropping them asap.

Upvotes: 0

Related Questions