Skip to content
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

maxconn option does not limit simultaneous connections #9

Open
tdryer opened this issue Jun 26, 2021 · 1 comment
Open

maxconn option does not limit simultaneous connections #9

tdryer opened this issue Jun 26, 2021 · 1 comment

Comments

@tdryer
Copy link
Contributor

tdryer commented Jun 26, 2021

The --maxconn N option does not limit the number of simultaneous connections as described.

This value is being used as the backlog parameter to listen. At least on Linux, this does not limit the number of concurrent connections, because once a connection is accepted, it's no long part of the pending connection queue.

One way to fix this would be to count the number of open connections, and avoid adding the listening socket to the file descriptor set if the count reaches the maximum.

Here's a Python script to reproduce the issue:

import socket

PORT = 8080

def main():
  request = b'GET /darkhttpd.c HTTP/1.1\r\n\r\n'
  sockets = []
  while True:
      s = socket.socket()
      s.settimeout(1)
      s.connect(("", PORT))
      s.send(request)
      data = s.recv(1024)
      sockets.append(s)
      print('{} connections open...'.format(len(sockets)))

if __name__ == '__main__':
    main()
@emikulic
Copy link
Owner

Yep, you're right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants