{"record":{"id":"c023b8c7391a06d8","repo":"nats-io/nats-server","slug":"server-is-not-running","errorCode":null,"errorMessage":"server is not running","messagePattern":"server is not running","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":175,"sourceCode":"\tErrClientOrRouteConnectedToGatewayPort = errors.New(\"attempted to connect to gateway port\")\n\n\t// ErrWrongGateway represents an error condition when a server receives a connect\n\t// request from a remote Gateway with a destination name that does not match the server's\n\t// Gateway's name.\n\tErrWrongGateway = errors.New(\"wrong gateway\")\n\n\t// ErrGatewayNameHasSpaces signals that the gateway name contains spaces, which is not allowed.\n\tErrGatewayNameHasSpaces = errors.New(\"gateway name cannot contain spaces\")\n\n\t// ErrNoSysAccount is returned when an attempt to publish or subscribe is made\n\t// when there is no internal system account defined.\n\tErrNoSysAccount = errors.New(\"system account not setup\")\n\n\t// ErrRevocation is returned when a credential has been revoked.\n\tErrRevocation = errors.New(\"credentials have been revoked\")\n\n\t// ErrServerNotRunning is used to signal an error that a server is not running.\n\tErrServerNotRunning = errors.New(\"server is not running\")\n\n\t// ErrServerNameHasSpaces signals that the server name contains spaces, which is not allowed.\n\tErrServerNameHasSpaces = errors.New(\"server name cannot contain spaces\")\n\n\t// ErrBadMsgHeader signals the parser detected a bad message header\n\tErrBadMsgHeader = errors.New(\"bad message header detected\")\n\n\t// ErrMsgHeadersNotSupported signals the parser detected a message header\n\t// but they are not supported on this server.\n\tErrMsgHeadersNotSupported = errors.New(\"message headers not supported\")\n\n\t// ErrNoRespondersRequiresHeaders signals that a client needs to have headers\n\t// on if they want no responders behavior.\n\tErrNoRespondersRequiresHeaders = errors.New(\"no responders requires headers support\")\n\n\t// ErrClusterNameConfigConflict signals that the options for cluster name in cluster and gateway are in conflict.\n\tErrClusterNameConfigConflict = errors.New(\"cluster name conflicts between cluster and gateway definitions\")\n","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L157-L193","documentation":"ErrServerNotRunning signals that an operation was attempted while the server (or the subsystem handling the request) is not running. JetStream API request handling returns it when `s.sys == nil` — i.e., the server has no active system account/eventing and is effectively not serving (server/jetstream.go:1208) — and JetStream cluster internals treat it as a shutdown signal to abandon inflight catchup work (server/jetstream_cluster.go:4106).","triggerScenarios":"Calling JetStream account/API methods during server shutdown or before the system account/eventing is initialized; cluster message handlers running after the server was shut down; issuing API requests to a node that is being stopped.","commonSituations":"Monitoring/JetStream clients hitting a node mid-rolling-restart; embedded NATS servers queried before s.Start() completes or after Shutdown(); graceful shutdown racing with background JetStream maintenance.","solutions":["Ensure the server is fully started (system account enabled) before issuing JetStream API calls.","Detect shutdown and stop retrying: treat ErrServerNotRunning as a terminal condition and reconnect to another node.","For embedded usage, gate calls on server readiness (e.g. s.ReadyForConnections(timeout)).","If it appears during shutdown tests, synchronize Shutdown() with in-flight request completion (WaitForShutdown)."],"exampleFix":"// before\ninfo, _ := js.AccountInfo()\n// after\nif nc.Status() == nats.CONNECTED && srvReady {\n    info, err := js.AccountInfo()\n    if errors.Is(err, ErrServerNotRunning) { /* stop and reconnect */ }\n}","handlingStrategy":"retry","validationCode":"// Gate calls on readiness:\nif !srv.ReadyForConnections(10 * time.Second) { return errors.New(\"server not ready\") }\n// and check client state:\nif nc.Status() != nats.CONNECTED { return errors.New(\"client not connected\") }","typeGuard":null,"tryCatchPattern":"info, err := js.AccountInfo()\nif errors.Is(err, ErrServerNotRunning) {\n    // treat as terminal for this node: backoff, then reconnect to another server\n    time.Sleep(backoff)\n    nc.Reconnect()\n}","preventionTips":["Drain/monitor nodes during rolling restarts so clients fail over instead of hitting a stopping server.","Use connection-lost callbacks to suspend JetStream calls until reconnected.","For embedded servers, serialize start/stop lifecycle against API callers.","Prefer official client APIs (which queue requests) over raw system requests during shutdown."],"tags":["nats","jetstream","server-lifecycle","shutdown"],"backgroundTag":"server-not-running","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}