Wait for IRC listener cleanup and HTTP shutdown on stop (closes #159)
check / check (push) Canceled after 0s

Stopping the server returned before the IRC listener's connections had
run their cleanup, and the database closed under them, so their
sessions, clients and channel memberships stayed and their nicks stayed
taken after a restart.

The IRC listener's stop now waits up to five seconds for every
connection's cleanup, which now runs on a context that stopping does
not cancel. The HTTP server's stop hook now runs Shutdown itself and
waits for it; httpServer is set before serving starts, and the server's
own signal watcher, which raced fx's stop hooks, is gone.

Model: opus-5-5
This commit is contained in:
2026-10-20 19:46:40 +00:00
parent 292f1eb7a9
commit 3f936925b9
6 changed files with 336 additions and 49 deletions
+33 -1
View File
@@ -1,6 +1,13 @@
package server
import "github.com/go-chi/chi/v5"
import (
"context"
"log/slog"
"net/http"
"github.com/go-chi/chi/v5"
"sneak.berlin/go/neoirc/internal/config"
)
// NewTestSPAServer creates a Server whose router serves only
// the embedded web client.
@@ -10,3 +17,28 @@ func NewTestSPAServer() *Server {
return srv
}
// NewTestHTTPServer creates a Server whose router serves
// handler at / and whose HTTP server listens on port once
// Start is called.
func NewTestHTTPServer(port int, handler http.HandlerFunc) *Server {
router := chi.NewRouter()
router.Get("/", handler)
return &Server{
log: slog.New(slog.DiscardHandler),
router: router,
params: Params{Config: &config.Config{Port: port}},
}
}
// Start starts the HTTP server, as the start hook does once
// the router is built.
func (srv *Server) Start() {
srv.startHTTP()
}
// Stop does what the stop hook does.
func (srv *Server) Stop(ctx context.Context) {
srv.cleanShutdown(ctx)
}