diff --git a/collector/flake.go b/collector/flake.go index c026ad1..da3dc02 100644 --- a/collector/flake.go +++ b/collector/flake.go @@ -1,6 +1,7 @@ package collector import ( + "context" "encoding/json" "log/slog" "os" @@ -182,7 +183,10 @@ func (c *FlakeCollector) collectRevisionBehind(ch chan<- prometheus.Metric, data } func fetchFlakeMetadata(flakeURL string) (*flakeMetadata, error) { - cmd := exec.Command("nix", "flake", "metadata", "--json", flakeURL) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + cmd := exec.CommandContext(ctx, "nix", "flake", "metadata", "--json", flakeURL) output, err := cmd.Output() if err != nil { return nil, err diff --git a/main.go b/main.go index a692b9e..edafe92 100644 --- a/main.go +++ b/main.go @@ -47,8 +47,11 @@ func main() { }) server := &http.Server{ - Addr: cfg.ListenAddr, - Handler: mux, + Addr: cfg.ListenAddr, + Handler: mux, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + IdleTimeout: 60 * time.Second, } // Handle shutdown gracefully