quit on leave

This commit is contained in:
Branden J Brown 2025-03-14 23:10:49 -04:00
parent bd2085ee87
commit c0afd85f11

View File

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