Skip to content

Support listening on file descriptors#380

Merged
mholt merged 1 commit into
caddyserver:masterfrom
gucci-on-fleek:file-descriptor-listen
May 7, 2026
Merged

Support listening on file descriptors#380
mholt merged 1 commit into
caddyserver:masterfrom
gucci-on-fleek:file-descriptor-listen

Conversation

@gucci-on-fleek
Copy link
Copy Markdown
Contributor

Fixes caddyserver/caddy#7525.

I've tested this with the following Caddyfile

{
	debug

	servers {
		trace
	}

	acme_ca https://acme-staging-v02.api.letsencrypt.org/directory

	auto_https disable_redirects
	default_bind fd/4 {
		protocols h1 h2
	}
}

http:// {
	bind fd/3
	redir https://{host}{uri} permanent
}

testing.958386.xyz { # Replace with your own domain
	log {
		level DEBUG
		format console
	}

	respond "Hello, world!"
}

by running the following command:

$ xcaddy build master --with=github.com/caddyserver/certmagic=.
$ systemd-socket-activate --now --listen=0.0.0.0:80 --listen=0.0.0.0:443 ./caddy run --config=./Caddyfile

I confirmed that

  1. I could not get a certificate without this commit.
  2. With this commit applied, I could get a freshly-issued certificate, and Caddy served it properly.
  3. I could still get fresh certificates in the regular non-socket-activation case.
  4. The tests I added all pass.

I've only tested this on Linux x86_64, but other platforms should hopefully be fine. The Dup code is fairly ugly, and I'm not 100% sure if it's necessary or not, but I know that closing someone else's file descriptors is a bad idea, so I added it just to be safe.

mholt
mholt previously approved these changes May 5, 2026
Copy link
Copy Markdown
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this is good overall; just a random question that I might want to look into, since it could be indicative of something sloppy I did elsewhere.

We just need the tests to pass first!

Comment thread solvers.go Outdated
Comment thread solvers_test.go Outdated
@gucci-on-fleek gucci-on-fleek force-pushed the file-descriptor-listen branch from eb78b10 to 83be062 Compare May 7, 2026 07:52
@gucci-on-fleek
Copy link
Copy Markdown
Contributor Author

Whoops, missed pushing some of my changes to the tests, let's see if they pass now. (They've always passed locally, it's only in GitHub Actions where they're failing)

Copy link
Copy Markdown
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I know how that goes. Thanks!

@mholt mholt merged commit 9b6be22 into caddyserver:master May 7, 2026
6 checks passed
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.

Caddy 2.11.1: socket activation problems with ACME

2 participants