Go listens on any unspecified address with one socket that answers IPv4 and IPv6, so BIND_ADDRESS=0.0.0.0 also bound every IPv6 address, which the README says it does not. The listener now uses tcp4 for an IPv4 address; :: still binds both. The server's start hook suppresses contextcheck, as the other start hooks do. The image's health check asked for localhost, which wget reached over ::1 only, so it now asks for 127.0.0.1. The README says what that means for a loopback bind in a container, drops the bindv6only condition from :: (Go sets that socket option itself), and names an ss check. Model: opus-5-5
This commit is contained in:
+28
-1
@@ -1,9 +1,11 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@@ -39,6 +41,21 @@ func (s *Server) listenAddr() string {
|
||||
)
|
||||
}
|
||||
|
||||
// listenNetwork returns the network the HTTP listener binds on, "tcp4"
|
||||
// for an IPv4 BindAddress and "tcp" for any other.
|
||||
//
|
||||
// On "tcp", Go binds 0.0.0.0 with a socket that answers IPv6 as well,
|
||||
// exactly as it binds ::. "tcp4" keeps 0.0.0.0 to IPv4, which is what
|
||||
// the README says it means. :: stays on "tcp" and answers both.
|
||||
func (s *Server) listenNetwork() string {
|
||||
addr, err := netip.ParseAddr(s.params.Config.BindAddress)
|
||||
if err == nil && addr.Is4() {
|
||||
return "tcp4"
|
||||
}
|
||||
|
||||
return "tcp"
|
||||
}
|
||||
|
||||
// newHTTPServer builds the HTTP server for this Server's
|
||||
// configuration.
|
||||
//
|
||||
@@ -67,7 +84,17 @@ func (s *Server) serveUntilShutdown() {
|
||||
|
||||
s.log.Info("http begin listen", "listenaddr", s.httpServer.Addr)
|
||||
|
||||
err := s.httpServer.ListenAndServe()
|
||||
// ListenAndServe always listens on "tcp", which would undo
|
||||
// listenNetwork.
|
||||
var listenCfg net.ListenConfig
|
||||
|
||||
listener, err := listenCfg.Listen(
|
||||
context.Background(), s.listenNetwork(), s.httpServer.Addr,
|
||||
)
|
||||
if err == nil {
|
||||
err = s.httpServer.Serve(listener)
|
||||
}
|
||||
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
s.log.Error("listen error", "error", err)
|
||||
s.shutdownWithFailure()
|
||||
|
||||
Reference in New Issue
Block a user