-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Implement issue #6296 passing FDs / socket activation #6507
Conversation
link to issue: #6296 |
|
It works for a local HTTP and HTTPS connections with this Caddyfile:
this
and this test command: I have not gotten h3 to work alongside h1 and h2 with |
Ok, I think it works with h3 now. I split
I need to double check that the h3 socket is actually working, because my browser doesn't like it. But http/https on h1/h2 is definitely working for any combination of binds, tls, inet and unix domain sockets I have tried. |
caddy.go
Outdated
// sliceContains returns true if needle is in haystack. | ||
func SliceContains(haystack []string, needle string) bool { | ||
for _, s := range haystack { | ||
if s == needle { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need this function be exposed outside Caddy. Let's move it to internal
. Better now than later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could use this new generic function: https://pkg.go.dev/slices#Contains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, looks like slices is used throughout caddy already. I'll replace SliceContains with slices.Contains.
modules/caddyhttp/server.go
Outdated
// Default: `[[h1 h2 h3]...]` | ||
Protocols [][]string `json:"protocols,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change. It breaks existing configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it is hard to determine how to create each listener if they all share one list of protocols for each server. One alternative could be to leave Protocols
alone and add a new list, ListenProtocols
, which contains a sublist of Protocols
for each address in Listen
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be changed in this way; but do we need to at all? Protocols are more of a server configuration than having to do with the individual listeners.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main case it handles is that with h3 enabled, a server with a tcp listen address will also bind an additional socket to the udp address with the same host:port. but if you are using socket activation, you will have two separate fds for that tcp and udp address, and not want one to be bound implicitly. so separating the protocols lets you disable h3 for the tcp address and enable h3 for the udp address explicitly. and with the change you can enable h1/h2 for a unix socket and h3 for a unixgram socket on the same server, which was not allowed before even though caddy can handle it just fine.
so for these cases, the network of an individual listener does change how its protocols are handled quite a bit. currently, the only place where Server.protocol
is called to do something other than set up a listener, is to check if h2 was enabled without h1.
ok, this puts the config provisioning/defaults for Server.Socket and Server.Protocols where I think they need to be. I can make Server.Protocols a []string again to lessen the breaking config change, but the individual protocol global server options will still have to be stored separately somewhere, say Server.ListenProtocols. This is for fd passing, I need a way to tell apart an h1/h2 TCP socket with an implicit h3 UDP socket bound to the same host:port, vs. two separate h1/h2 TCP and h3 UDP sockets each with their own fds. This way h3 can still be enabled for a TCP socket to indicate the first case, but it can be disabled if that TCP socket is passed an fd so it isn't bound twice. |
is it ok to change the shape of Server.Protocols? it just isn't very straightforward to enable h3 for a whole server, that can bind to addresses with both tcp and udp networks. each server needs to know which http should serve which socket with which fd, not the union of protocols enabled for all its listen addresses. the other change this causes is that an h3 UDS socket will have to use the correct the best way to do this is probably to add |
another way to approach config would be to add protocol flags to the bind directive, I like this config more, so I'll update the PR with it if we all agree on how
and this also allows a h1+h2+h3 site to be served entirely with uds's:
|
here is an example Caddyfile:
|
or I could add a new directive |
Did you mean to close this? Sorry I've been absent. Very busy with a lot to catch up on. |
no problem. I'm going to reopen or make a new PR with a separate listen_protocols config key, an optional block after |
Ah neat. Sounds good, will be happy to review when you're ready! |
closed in favor of #6543 |
This PR enables socket activation by adding a global server option that can be used to open the fd of an existing socket, instead of binding a new socket, for any network address. Example
Caddyfile
: