-
-
Notifications
You must be signed in to change notification settings - Fork 178
Pause server #448
base: master
Are you sure you want to change the base?
Pause server #448
Conversation
Add a `pause`/`resume` API to `Server` which removes/adds a server's listening sockets on its event loop selector. This facility allows DoS prevention from SYN flooding connection herds. Add `max_connections` kwarg to `loop.create_server` and `Server` which controls pause/resume behavior when not `None`. Notes: 1. Using Server.pause/resume and create_server(max_connections) are mutually exclusive. 2. The listen backlog and accept semantics are not taken into consideration. As a result the actual number of connections established will vary and should be considered platform and/or event loop dependant.
Fix Server create for unix sockets and add support for max_connections.
We'll need tests for this new functionality. I think that |
@1st1 |
But what criteria do you use to pick up a sound number for |
I'd expect it to be mostly application dependant. It would obviously need to be less than the In my particular case setting |
I'm writing some tests btw, but before I get too far, are you generally okay with the location of the functionality and the way the start_serving arguments are stored in |
I think that the way the patch is stuctured now is fine. But before you get too far, let's wait until @gvanrossum gives this idea a green light. |
Tests for create_server(max_connections=number) and Server.pause/resume.
Refactored a bit to share most the logic with the TCP server.
Should I be evangelizing this? I'd like to see it get accepted. @gvanrossum has publicly stated he's not focused on asyncio as much as he used to be, so perhaps there are other stakeholders we can bother? |
@gvanrossum What do you think on this one? 3.7? |
Definitely 3.7. Until then this could easily be implemented as a separate AbstractServer subclass. |
3.7 is fine, let me know how I can help or what I should do, if anything. Re: subclassing AbstractServer, I believe I brought this up in the forum in the context of allowing a user to bring their own Server subclass to |
@gvanrossum This is something we can still do in 3.6, right? IIUC we can add a |
For something meant to go into the stdlib at 3.7, copypasta is probaby not
a problem.
|
Please reopen this PR at https://github.com/python/cpython. This repo is going to be deleted soon. |
Re: https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!topic/python-tulip/btGHbh5kUUM
Tests pass. I sort of wish the pause and resume functions could elegantly live on the event loop and not on the Server object, but it seems to be the best contextual storage for all the listening sockets.
Also I'm not sure max_connections on create_server is justifiable or even a good name, but it was immediately useful to my particular problem and I imagine it could be to others too. So I left it in.