-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limiting the number of TCP connections #24
Comments
Hi! I'm not quite sure what you'd like to achieve... Are you trying to artificially limit the number of open TCP connections to a safe value (by forcibly closing old ones), or are you trying to circumvent the problem of sockets in the TIME_WAIT state? Solving the latter case is quite easy because you can use TCP_TW_REUSE to control this. Maybe I'm wrong though and @zonyitoo has a better idea, but I'm currently working on an coio overhaul anyways, because of a similiar issue (see #22). This will take another ~2 months though, because I'm currently in the middle of learning for my exams... |
Hmm, what would you do if you are using normal C APIs? |
If you use |
In C, I would indeed |
Ah, I see. So if one Calling
You may try some ways in below:
|
I don't think your 3 solutions will work, because if a coroutine is still stuck in I/O it will never anymore be woken up after you called |
Indeed, Dropping new connections makes servers trivially vulnerable to DoS attacks, while closing previous connections somewhat mitigates them by giving a chance for some legitimate queries to get in. This is one of the things all DNS resolvers and servers are doing in order to mitigate the constant attacks they are facing. |
I have implemented an experimental version to solve this problem, please check this test. This would provide a way to set a timeout time for an I/O object. |
This is awesome! |
Still in experimental stage, please ensure it works well |
Timeouts (issue #22) will surely help in making sure that clients do not use something like the Slowloris attack, but does this really solve this issue? Because this issue needs a solution for deterministically closing old connections (even if they are in use). Also - and I think that's the "sad" part: As you know, @zonyitoo, I've been working on the eventloop-overhaul and large parts of your branch won't work with this (because I'm going to remove oneshot polling due to the huge performance impact it has). 😕 |
The only thing you have to ensure is API compatibility, so you can surely reimplement all the internal in coio as you wish. Yes, removing oneshot polling is a good idea to improve performance, but this will surely add complexity in the implementation. You could just ignore my branch, it just an experimental implementation to express my idea. I haven't seen another facilities to dump Slowloris attack. To prevent server from being overload, one solution is to add fast-reject ability. The server will close the accepted connection immediately after accepting when it is already overloaded. This fast-reject policy won't need to be implemented in coio, it could be implemented in any server implementation. |
Yeah this "fast-reject policy" is what I would have done too. But since @jedisct1 brought up this issue I've noticed how flawed this is... Because if an attacker manages to open a large number of connections to your server until it becomes exhausted, new connections will be dropped. Thus you've created a system which easily succumbs to a DoS. In the end I think that this issue might take some time... The problem is that coio uses and should probably continue using suspend-down coroutines, although they make awaiting 2 different async. things (like for instance simultaneously awaiting a "close" signal through a channel and a Although I have an idea how to concurrently abort read/writes from another coroutine it's rather... "simple". So... For the time being I think coio will probably only have read/write timeouts and a "real" solution for this will come later. |
Well, looking forward to see that. I don't think there is a better solution for the two DoS attack situations, which are: large number of connections and rapidly create new connections. I am very curious about the solution in those commercial servers. |
@lhecker BTW, I think we should keep this crate simple and do what it have to be done. I am also planning to build a server framework with coio. |
Yeah of course! |
coroutine-rs is my first project, but soon I found that it is very useless to use coroutine without I/O. Also it is very hard to separate coroutine's basic facilities outside a coroutine's scheduler. So I separate the most important part to context-rs. You can easily build a coroutine library with the context-rs. |
Hey @jedisct1! Just a heads up: We developed a "coroutine" barrier that works similiar to the well known thread barriers. We are (more than likely) going to use those to wait for the completion of async. I/O in the future. |
This is fantastic news! |
Hi Zonytoo,
I'd like to use coio in a public-facing service accepting anonymous TCP connections.
If only to avoid file descriptors exhaustion, there has to be a limit on the maximum amount of open connections.
While just closing a socket after having accepted it if we get close to the limit is an option, a better practice is to close the oldest connection instead.
However, I didn't see any obvious ways to do this when using coio. How would you do TCP reuse?
The text was updated successfully, but these errors were encountered: