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

core: Support Unix domain socket HTTP server listener #798

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/internal/helpers/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func ValidateHostList(hosts []string) bool {
// ValidateHostPort returns true if the provided string is of the form "hostname:port", where hostname is a valid
// hostname or IP address (as parsed by ValidateIP or ValidateHostname), and port is a valid integer.
func ValidateHostPort(host string, allowBlankHost bool) bool {
if strings.HasPrefix(host, "unix:") {
return true
}

// Must be hostname:port, ipv4:port, or [ipv6]:port. Optionally allow blank hostname
hostname, portString, err := net.SplitHostPort(host)
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions core/internal/httpserver/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ func (hc *Coordinator) Start() error {
listeners := make(map[string]net.Listener)

for name, server := range hc.servers {
ln, err := net.Listen("tcp", hc.servers[name].Addr)
network := "tcp"
if strings.HasPrefix(hc.servers[name].Addr, "unix:") {
network = "unix"
hc.servers[name].Addr = hc.servers[name].Addr[len("unix:"):]
}

ln, err := net.Listen(network, hc.servers[name].Addr)
if err != nil {
hc.Log.Error("failed to listen", zap.String("listener", hc.servers[name].Addr), zap.Error(err))
for _, listenerToClose := range listeners {
Expand All @@ -184,10 +190,14 @@ func (hc *Coordinator) Start() error {
}
return err
}

hc.Log.Info("started listener", zap.String("listener", ln.Addr().String()))
listeners[name] = tcpKeepAliveListener{
Keepalive: server.IdleTimeout,
TCPListener: ln.(*net.TCPListener),
listeners[name] = ln
if network == "tcp" {
listeners[name] = tcpKeepAliveListener{
Keepalive: server.IdleTimeout,
TCPListener: ln.(*net.TCPListener),
}
}
}

Expand Down
Loading