Skip to content

fix(sshd): serve connections concurrently with a login grace time - #3746

Merged
BaseMax merged 4 commits into
mainfrom
fix/sshd-concurrency
Nov 21, 2026
Merged

BaseMax merged 4 commits into
mainfrom
fix/sshd-concurrency

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 21, 2026

Copy link
Copy Markdown
Member

sshd.Serve handled one connection at a time and nothing limited how long a connection could take to log in, so a single client that connected and stayed silent blocked every other login.

Now Serve hands each accepted connection to a pool worker, up to the new max_connections (default 64); connections over the cap are closed at once. ServeConnection starts a watchdog that shuts the socket if the handshake and authentication are not done within the new login_grace_ms (default 120000, 0 turns it off; also on ssh.ServerConfig). ServeOnce still serves one connection on the calling thread. sftpd gets the defaults but does not expose the two fields yet.

Tested with a main-built compiler: new tests/en/stdlib/sshd_concurrent (an idle connection does not stop a second client from getting the banner, and is closed after the grace time), plus sftpd_basic, ssh_selftest, ssh_coverage, check on windows and darwin targets. By hand: with one idle nc open, ssh-keyscan answers in 0.1 s (main: no answer) and the idle socket closes after the grace time; with max_connections 2 the third connection is closed; three OpenSSH logins finish while a fourth session runs sleep 4. sshd_basic is already red on main (client cannot negotiate ed25519) and ends the same way here, without hanging.

This overlaps #3739 in _ssh_config and the sshd docs. When both land, the host key from #3739 has to be carried through _Shared into _ssh_config in _serve_next; passing an empty key makes every connection refused, not hang.

@BaseMax
BaseMax requested a review from a team as a code owner November 21, 2026 06:50
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bbf8a3b1-14d6-44b5-9d89-638325075be5
Commits

Reviewing files that changed from the base of the PR and between 87fe711 and 1f6d1dd.

Files ignored due to path filters: 1

  • tests/en/stdlib/sshd_concurrent.out is excluded by !**/*.out
Files selected for processing: 6

  • std/ssh/server.salam
  • std/sshd/sshd.salam
  • tests/en/stdlib/sshd_concurrent.salam
  • tools/salam/std-coverage-docs-baseline.txt
  • website/content/en/std/101-sshd.txt
  • website/content/fa/std/101-sshd.txt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@BaseMax
BaseMax merged commit 1934c93 into main Nov 21, 2026
15 checks passed
@BaseMax
BaseMax deleted the fix/sshd-concurrency branch November 21, 2026 07:14
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