diff --git a/main.go b/main.go index eb13a6e..d42492b 100644 --- a/main.go +++ b/main.go @@ -135,6 +135,7 @@ func addrflag(ip string, p uint64) (netip.AddrPort, error) { } func cliJoin(ctx context.Context, cmd *cli.Command) error { + ctx, cancel := context.WithCancel(ctx) addr, err := addrflag(cmd.String("ip"), cmd.Uint("p")) if err != nil { return err @@ -170,6 +171,7 @@ func cliJoin(ctx context.Context, cmd *cli.Command) error { } go func() { slog.InfoContext(ctx, "HTTP API server", slog.Any("addr", l.Addr())) + defer cancel() err := srv.Serve(l) if err == http.ErrServerClosed { return @@ -189,7 +191,7 @@ func cliJoin(ctx context.Context, cmd *cli.Command) error { }() <-ctx.Done() t.Stop() - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) defer cancel() return srv.Shutdown(ctx) }