{"record":{"id":"8621acfa74a5bd25","repo":"semaphoreui/semaphore","slug":"503-service-unavailable","errorCode":null,"errorMessage":"503 Service Unavailable","messagePattern":"503 Service Unavailable","errorType":"http","errorClass":null,"httpStatus":503,"severity":"error","filePath":"pkg/metrics/metrics.go","lineNumber":72,"sourceCode":"\t\treturn\n\t}\n\n\tif oldStatus == task_logger.TaskRunningStatus {\n\t\tm.tasksRunning.Dec()\n\t}\n\n\tif newStatus == task_logger.TaskRunningStatus {\n\t\tm.tasksRunning.Inc()\n\t}\n\n\tif newStatus.IsFinished() && !oldStatus.IsFinished() {\n\t\tm.tasksTotal.WithLabelValues(string(newStatus)).Inc()\n\t}\n}\n\nfunc (m *Metrics) ServeHTTP(w http.ResponseWriter, r *http.Request) {\n\tif m == nil || m.handler == nil {\n\t\thttp.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)\n\t\treturn\n\t}\n\tm.handler.ServeHTTP(w, r)\n}\n","sourceCodeStart":54,"sourceCodeEnd":77,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/pkg/metrics/metrics.go#L54-L77","documentation":"Returned by the Metrics ServeHTTP handler in pkg/metrics/metrics.go when the receiver is nil or its embedded prometheus handler was never initialised (e.g. the Metrics object was constructed without registering a registry). It is a guard that degrades gracefully: instead of panicking on scrape, it answers HTTP 503 so the scraper knows metrics are temporarily unavailable rather than silently scraping an empty page.","triggerScenarios":"Thrown at pkg/metrics/metrics.go:72 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure metrics.New()/registration runs before the handler is mounted on the HTTP mux","Check that the Metrics value is not a nil pointer (a common cause is returning a nil *Metrics from a failed constructor and then using it as a handler)","Wire a live *prometheus.Registry into the handler during service startup so ServeHTTP never sees a nil inner handler","Scrapers should treat 503 from this endpoint as 'metrics not ready' and retry after startup completes"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}