Skip to content

maxconn option does not limit simultaneous connections #9

Description

@tdryer

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions