Skip to content

feat: add --maxclients option to limit concurrent fork connections#68

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/add-maxclients-option
Draft

feat: add --maxclients option to limit concurrent fork connections#68
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/add-maxclients-option

Conversation

@toddr-bot
Copy link
Copy Markdown

@toddr-bot toddr-bot commented Apr 15, 2026

What

Adds a --maxclients=N option that limits the number of concurrent child processes in fork mode.

Why

Fork-mode servers currently have no connection limit — every incoming connection spawns a child unconditionally. Under connection floods (intentional or accidental), this can exhaust system resources. Every serious daemon framework (Apache, vsftpd, postfix) has this guard.

How

  • active_children counter in Bind(), incremented on fork, decremented in SigChildHandler
  • When maxclients is set and the limit is reached, connections are accepted (to drain the kernel queue) then immediately closed with an error log
  • When children exit and SIGCHLD fires, slots free up and new connections are accepted again
  • Works alongside prefork mode (--childs) which has its own fixed pool

Testing

  • New t/maxclients.t: starts server with --maxclients=2, verifies 3rd connection is rejected, verifies recovery after a slot frees up (6 tests)
  • Full test suite passes

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 136 insertions(+)

Code scan: 2 issue(s) found

  • t/maxclients.t:70 — debug print statement
  • t/maxclients.t:97 — debug print statement

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

… mode

Without a connection limit, fork-mode servers are vulnerable to resource
exhaustion from connection floods — each new connection spawns a child
process unconditionally.  The new --maxclients=N option tracks active
children and rejects connections when the limit is reached, logging an
error and closing the socket immediately.  When children exit and slots
free up, new connections are accepted again.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant