cheroot
cheroot copied to clipboard
Make it possible to set SO_REUSEPORT to the server's socket
β What kind of change does this PR introduce?
- [ ] π bug fix
- [x] π£ feature
- [ ] π docs update
- [ ] π tests/coverage improvement
- [ ] π refactoring
- [ ] π₯ other
π What is the related issue number (starting with #
)
Resolves #504
β What is the current behavior? (You can also link to an open issue here)
Cheroot cannot be used in infrastructure where bind address for it allocated and kept by some different process.
main.py:
s = socket.socket(family)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
s.bind(('127.0.0.1', 1234))
subprocess.run(['python3', 'server.py', '127.0.0.1', '1234'])
server.py:
addr = (argv[0], int(argv[1]))
server = wsgi.Server(addr, wsgi_app)
server.start() # fails, socket already in use
β What is the new behavior (if this is a feature change)?
Cheroot can optionally re-use port:
main.py:
s = socket.socket(family)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
s.bind(('127.0.0.1', 1234))
subprocess.run(['python3', 'server.py', '127.0.0.1', '1234'])
server.py:
addr = (argv[0], int(argv[1]))
server = wsgi.Server(addr, wsgi_app, reuse_port=True) # a new option reuse_port
server.start() # works, SO_REUSEPORT has been set
π Contribution checklist:
(If you're a first-timer, check out this guide on making great pull requests)
- [x] I wrote descriptive pull request text above
- [x] I think the code is well written
- [x] I wrote good commit messages
- [x] I have squashed related commits together after the changes have been approved
- [x] Unit tests for the changes exist
- [ ] Integration tests for the changes exist (if applicable)
- [x] I used the same coding conventions as the rest of the project
- [x] The new code doesn't generate linter offenses
- [x] Documentation reflects the changes
- [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences