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 {
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)
}