{"record":{"id":"1bc95930e2000e3e","repo":"nautechsystems/nautilus_trader","slug":"socket-endpoint-cannot-exceed-endpoint-max-len-b","errorCode":null,"errorMessage":"Socket endpoint cannot exceed {ENDPOINT_MAX_LEN} bytes","messagePattern":"Socket endpoint cannot exceed (.+?) bytes","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/messages/system/socket.rs","lineNumber":32,"sourceCode":"// -------------------------------------------------------------------------------------------------\n\nuse std::{any::Any, fmt::Display};\n\nuse nautilus_core::{UUID4, UnixNanos};\nuse nautilus_model::identifiers::{ClientId, TraderId, Venue};\nuse ustr::Ustr;\n\n#[cfg(any(feature = \"live\", test))]\nconst ENDPOINT_MAX_LEN: usize = 128;\n\n#[cfg(any(feature = \"live\", test))]\npub(crate) fn socket_endpoint(endpoint: &str) -> anyhow::Result<Ustr> {\n    if endpoint.is_empty() {\n        anyhow::bail!(\"Socket endpoint cannot be empty\");\n    }\n\n    if endpoint.len() > ENDPOINT_MAX_LEN {\n        anyhow::bail!(\"Socket endpoint cannot exceed {ENDPOINT_MAX_LEN} bytes\");\n    }\n\n    if !endpoint\n        .bytes()\n        .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_'))\n    {\n        anyhow::bail!(\"Socket endpoint must contain only ASCII letters, digits, '.', '-', or '_'\");\n    }\n\n    Ok(Ustr::from(endpoint))\n}\n\n/// Command requesting reconnect of one socket endpoint owned by one client.\n#[repr(C)]\n#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]\n#[cfg_attr(\n    feature = \"python\",\n    pyo3::pyclass(module = \"nautilus_trader.common\", from_py_object)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/messages/system/socket.rs#L14-L50","documentation":"socket_endpoint enforces a maximum endpoint length of ENDPOINT_MAX_LEN (128 bytes, compiled in for the live/test features). Endpoints longer than this limit are rejected because they would not fit the fixed-size constraints downstream (e.g. protocol fields or identifiers).","triggerScenarios":"Calling socket_endpoint with a string longer than 128 bytes, typically an over-long host label, concatenated key, or an accidentally pasted URL instead of a short endpoint identifier.","commonSituations":"Users putting a full URL (`tcp://host.example.com:7323`) into a field that expects a short endpoint name; generated names built by concatenating client/venue/ID components exceeding the cap.","solutions":["Shorten the endpoint string to at most 128 bytes; pass only the endpoint name, not a full URL.","If the name is programmatically composed, hash or truncate the composed segments before validation.","Validate length at config-load time to fail fast with a domain-specific message.","Confirm you are not swapping in an address where an endpoint identifier is expected."],"exampleFix":"// before\nlet ep = socket_endpoint(\"tcp://very-long-host-name.example.internal.trading.lan:7323\")?;\n// after\nlet ep = socket_endpoint(\"very-long-host-name\")?; // short identifier, <=128 bytes","handlingStrategy":"validation","validationCode":"const ENDPOINT_MAX_LEN: usize = 128;\nfn endpoint_len_ok(s: &str) -> bool { s.len() <= ENDPOINT_MAX_LEN }","typeGuard":"fn valid_endpoint(s: &str) -> bool { !s.is_empty() && s.len() <= 128 && s.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'.' | b'-' | b'_')) }","tryCatchPattern":"let ep = socket_endpoint(endpoint)\n    .map_err(|e| anyhow::anyhow!(\"endpoint '{endpoint}' rejected: {e}\"))?;","preventionTips":["Pass short endpoint identifiers, never full URLs or connection strings.","Cap generated names (hash/truncate composed segments) before validation.","Validate length in config loaders."],"tags":["validation","network","socket","rust"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}