From 84585b8034d0be8222687ba7d7d437cd544ac467 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sun, 3 May 2026 20:50:44 +0200 Subject: [PATCH] perf(service): move TLS cert generation off the startup path On constrained hardware (e.g. ARMv7), RSA key generation can block startup for minutes. HTTP now starts immediately; HTTPS is brought up in a background goroutine once cert generation completes. A log message informs the user that HTTPS will be available shortly after startup. Co-Authored-By: Claude Sonnet 4.6 --- cmd/soundtouch-service/main.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/soundtouch-service/main.go b/cmd/soundtouch-service/main.go index 9537d8e..c17df3c 100644 --- a/cmd/soundtouch-service/main.go +++ b/cmd/soundtouch-service/main.go @@ -460,20 +460,23 @@ func main() { initializeDefaultSources(ds) - tlsConfig, err := cm.GetServerTLSConfig(config.domains) - if err != nil { - log.Printf("Warning: Failed to setup TLS: %v", err) - } - startDeviceDiscovery(server) r := setupRouter(server) log.Printf("Go service starting on %s", config.serverURL) - if tlsConfig != nil { + // TLS cert generation can be slow on constrained hardware; run it in the + // background so the HTTP server is available immediately. + log.Printf("HTTPS setup running in background; %s will be available shortly", config.httpsServerURL) + go func() { + tlsConfig, err := cm.GetServerTLSConfig(config.domains) + if err != nil { + log.Printf("Warning: Failed to setup TLS: %v", err) + return + } startHTTPSServer(config.httpsAddr, r, tlsConfig, config.httpsServerURL) - } + }() return http.ListenAndServe(config.addr, r) },