Skip to content

Commit 4cea545

Browse files
committed
fix(misc): graceful pprof shutdown, Makefile and config comment syntax
Replace bare http.ListenAndServe in InitDebug with an http.Server that shuts down cleanly on context cancellation. Remove build from .PHONY in Makefile. Fix comment markers in config.yml.example from // to #.
1 parent b59a37d commit 4cea545

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Build and install the indexer and API
33
########################################################
44

5-
.PHONY: build build-indexer build-api clean
5+
.PHONY: build-indexer build-api clean
66

77
# Get git information
88
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")

config.yml.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# the indexer can listen to http or https
55
rpc: http://localhost:26657
66

7-
// Uncomment the following line to set a custom user agent
8-
// user_agent: gnoland-indexer
7+
# Uncomment the following line to set a custom user agent
8+
# user_agent: gnoland-indexer
99

1010
# Pool configuration
1111
# these are settings related to the database connection pool

indexer/main_operator/debug.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ import (
1414
func InitDebug(ctx context.Context) {
1515
l.Info().Msg("Debug mode started")
1616
go printMemStats(ctx, 5*time.Second)
17-
go http.ListenAndServe(":6060", nil)
17+
18+
server := &http.Server{Addr: ":6060"}
19+
go func() {
20+
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
21+
l.Error().Err(err).Msg("debug pprof server failed")
22+
}
23+
}()
24+
1825
<-ctx.Done()
26+
if err := server.Shutdown(context.Background()); err != nil {
27+
l.Error().Err(err).Msg("failed to shut down debug pprof server")
28+
}
1929
l.Info().Msg("Debug mode stopped")
2030
}
2131

0 commit comments

Comments
 (0)