{"record":{"id":"93681940ce4141eb","repo":"risingwavelabs/risingwave","slug":"nats-connection-status-is-not-connected-current-s","errorCode":null,"errorMessage":"Nats connection status is not connected, current status is {:?}","messagePattern":"Nats connection status is not connected, current status is (.+?)","errorType":"exception","errorClass":"ConnectorError","httpStatus":null,"severity":"error","filePath":"src/connector/src/source/nats/enumerator/mod.rs","lineNumber":64,"sourceCode":"\n        // check if the stream exists or allow create stream\n        let jetstream = NatsCommon::build_context_from_client(&client);\n        let _ = properties\n            .common\n            .build_or_get_stream(jetstream, properties.stream.clone())\n            .await?;\n        Ok(Self {\n            subject: properties.common.subject,\n            split_id: Arc::from(\"0\"),\n            client,\n        })\n    }\n\n    async fn list_splits(&mut self) -> ConnectorResult<Vec<NatsSplit>> {\n        // Nats currently does not support list_splits API, if we simple return the default 0 without checking the client status, will result executor crash\n        let state = self.client.connection_state();\n        if state != async_nats::connection::State::Connected {\n            bail!(\n                \"Nats connection status is not connected, current status is {:?}\",\n                state\n            );\n        }\n        // TODO: to simplify the logic, return 1 split for first version\n        let nats_split = NatsSplit {\n            subject: self.subject.clone(),\n            split_id: Arc::from(\"0\"), // be the same as `from_nats_jetstream_message`\n            start_sequence: NatsOffset::None,\n        };\n\n        Ok(vec![nats_split])\n    }\n}\n","sourceCodeStart":46,"sourceCodeEnd":79,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/source/nats/enumerator/mod.rs#L46-L79","documentation":"The NATS source enumerator's list_splits refuses to run when the underlying async_nats client is not in the Connected state. Returning a default split without this check would cause downstream executors to crash, so the connector fails fast with the actual connection state for diagnosis.","triggerScenarios":"Calling list_splits on a NatsSplitEnumerator whose client.connection_state() is anything other than async_nats::connection::State::Connected — e.g. before the initial connection is established, or after the broker connection dropped and has not reconnected.","commonSituations":"NATS broker is down or unreachable during source startup; network partition between RisingWave and NATS server; source started before NATS finishes accepting connections; TLS/auth rejected causing the client to sit in a reconnecting state.","solutions":["Verify the NATS server is running and reachable at the configured URL (e.g. nats://host:4222) with `nats server report` or by checking the broker process.","Check credentials/TLS settings — a failed auth handshake leaves the client in a non-Connected state.","Retry the operation after the async_nats client auto-reconnects; the connection status will return to Connected.","Inspect logs for the reported state (e.g. Connecting, Reconnecting, Disconnected) to pinpoint the connection problem."],"exampleFix":"// before\nbail!(\"Nats connection status is not connected, current status is {:?}\", state);\n// after (caller-side retry until connected)\nwait_until_connected(&client).await?; // retry loop honoring async_nats reconnect policy\nlet splits = enumerator.list_splits().await?;","handlingStrategy":"retry","validationCode":"if client.state() != async_nats::connection::State::Connected {\n    return Err(\"nats client not connected; retry after reconnect\");\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"connection status is not connected\") => retry_with_backoff(|| list_splits()).await,\n    other => other,\n}","preventionTips":["Health-check the NATS broker before starting or resuming sources.","Rely on async_nats auto-reconnect and back off/retry during non-Connected states.","Monitor connection-state events and alert on prolonged Disconnected/Reconnecting states.","Validate credentials and TLS config before deployment to avoid stuck reconnect loops."],"tags":["nats","network","connector","source"],"backgroundTag":"connection-refused","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}