Skip to content

Commit

Permalink
add timeouts (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Mar 4, 2024
1 parent 13a68c3 commit 8f41de2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ func main() {
logger.Printf("Serving /metrics on port %s and interface %s\n", adminPort, cli.Serve.Interface)
adminMux := http.NewServeMux()
adminMux.Handle("/metrics", promhttp.Handler())
logger.Fatal(http.ListenAndServe(cli.Serve.Interface+":"+adminPort, adminMux))
logger.Fatal(startHTTPServer(cli.Serve.Interface+":"+adminPort, adminMux))
}()
}
logger.Fatal(http.ListenAndServe(cli.Serve.Interface+":"+strconv.Itoa(cli.Serve.Port), nil))
logger.Fatal(startHTTPServer(cli.Serve.Interface+":"+strconv.Itoa(cli.Serve.Port), nil))
case "extract <input> <output>":
err := pmtiles.Extract(logger, cli.Extract.Bucket, cli.Extract.Input, cli.Extract.Minzoom, cli.Extract.Maxzoom, cli.Extract.Region, cli.Extract.Bbox, cli.Extract.Output, cli.Extract.DownloadThreads, cli.Extract.Overfetch, cli.Extract.DryRun)
if err != nil {
Expand Down Expand Up @@ -222,3 +222,14 @@ func main() {
}

}
func startHTTPServer(addr string, handler http.Handler) error {
server := &http.Server{
ReadTimeout: 10 * time.Second,
ReadHeaderTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 30 * time.Second,
Addr: addr,
Handler: handler,
}
return server.ListenAndServe()
}

0 comments on commit 8f41de2

Please sign in to comment.