Skip to content
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 #6573

Open
wants to merge 42 commits into
base: master
Choose a base branch
from

Conversation

MayCXC
Copy link

@MayCXC MayCXC commented Sep 15, 2024

third time's the charm ☘️

example Caddyfile:

{
	auto_https disable_redirects
	admin off
}

http://localhost {
	bind fd/{env.CADDY_HTTP_FD} {
		protocols h1
	}
	log
	respond "Hello, HTTP!"
}

https://localhost {
	bind fd/{env.CADDY_HTTPS_FD} {
		protocols h1 h2
	}
	bind fdgram/{env.CADDY_HTTP3_FD} {
		protocols h3
	}
	log
	respond "Hello, HTTPS!"
}

as seen above, two reserved networks fd and fdgram have been added. fd/3 creates a FileListener from fd 3, fdgram/4 creates a FilePacketConn from fd 4. this simplifies configuration compared to #6543 , but the "actual" host addresses are no longer visible. so, for health checks and the admin interface, fds are treated similarly to unix sockets.

this is a good thing i think, fds should be decoupled from the address they are bound to. separate config options can be added to override the origin address for health checks / the admin interface if needed.

link to issue: #6296

listen.go Outdated
Comment on lines 46 to 59
func() {
socketFilesMu.Lock()
defer socketFilesMu.Unlock()

socketFdWide := uintptr(fd)
var ok bool

socketFile, ok = socketFiles[socketFdWide]

if !ok {
socketFile = os.NewFile(socketFdWide, lnKey)
socketFiles[socketFdWide] = socketFile
}
}()
Copy link
Author

Choose a reason for hiding this comment

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

this is the only significantly changed behavior from #6543 ; listenReusable locks the fd number -> file map. this is similar to what reuseUnixSocket does with unixSockets, but there are no messy race conditions involving unlink or the filesystem. it just needs to ensure that every fd is opened at most once, so the lock prevents multiple reads before the first write.

listen_unix.go Outdated
Comment on lines 112 to 125
func() {
socketFilesMu.Lock()
defer socketFilesMu.Unlock()

socketFdWide := uintptr(socketFd)
var ok bool

socketFile, ok = socketFiles[socketFdWide]

if !ok {
socketFile = os.NewFile(socketFdWide, lnKey)
socketFiles[socketFdWide] = socketFile
}
}()
Copy link
Author

Choose a reason for hiding this comment

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

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