Hold Go's server privately in waf.Server and rproxy.Server (closes #437)
check / check (push) Failing after 1m42s

Neither Server embeds *http.Server any more. Each holds it as a private
field, is its handler, and has Serve, Shutdown, Close and ServeHTTP.
sww's serve hook takes the new daemonServer interface of those first
three, and fx provides each Server as it.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-20 00:33:14 +00:00
1 parent cc77435f2a
commit ad7ea4608b
15 files changed
+134 -54

No files matched your search

+9 -1
View File
@@ -95,12 +95,20 @@ func background(loop func(context.Context)) fx.Hook {
)
}
// daemonServer is the server a daemon runs, waf.Server or rproxy.Server: the
// methods of Go's http.Server that serve starts and stops it with.
type daemonServer interface {
Serve(listener net.Listener) error
Shutdown(ctx context.Context) error
Close() error
}
// serve serves requests on listener from the start. At the stop it gives the
// requests in progress shutdownTimeout to finish, then closes their
// connections. When serving fails, it logs why and sends the error to
// failed.
func serve(
lc fx.Lifecycle, server *http.Server, listener net.Listener,
lc fx.Lifecycle, server daemonServer, listener net.Listener,
processLog *slog.Logger, failed servingFailed,
) {
served := make(chan error, 1)
+7 -3
View File
@@ -4,7 +4,6 @@ import (
"context"
"log/slog"
"net"
"net/http"
"os"
"go.uber.org/fx"
@@ -44,8 +43,13 @@ func RunRProxy(ctx context.Context, params Params) int {
app := fx.New(
fx.Supply(cfg, processLog, requestLog{params.Stdout}, failed),
fx.Provide(
newRProxyServer,
func(server *rproxy.Server) *http.Server { return server.Server },
// run waits for rproxy.Server's reports, and serve takes it as a
// daemonServer.
fx.Annotate(
newRProxyServer,
fx.As(fx.Self()),
fx.As(new(daemonServer)),
),
newRProxyListener,
),
fx.Invoke(serve),
+2 -3
View File
@@ -6,7 +6,6 @@ import (
"io"
"log/slog"
"net"
"net/http"
"time"
"go.uber.org/fx"
@@ -97,8 +96,8 @@ func RunWAF(ctx context.Context, params Params) int {
newAlertQueue, newRuleFiles, newCoreRuleSet, newLookupFile,
newLimiter, newLedger, newAnomalyCounters,
newLists, newDNSBL, newAbuseIPDB, newRouteWatch,
newMetrics, newGeoJS, newWAFServer,
func(server *waf.Server) *http.Server { return server.Server },
newMetrics, newGeoJS,
fx.Annotate(newWAFServer, fx.As(new(daemonServer))),
newWAFListener, newStateFiles,
),
// fx stops hooks in the reverse of the order they were added in. The