nautechsystems/nautilus_trader · error · anyhow::Error
Socket endpoint cannot exceed {ENDPOINT_MAX_LEN} bytes
Error message
Socket endpoint cannot exceed {ENDPOINT_MAX_LEN} bytes What it means
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).
Source
Thrown at crates/common/src/messages/system/socket.rs:32
// -------------------------------------------------------------------------------------------------
use std::{any::Any, fmt::Display};
use nautilus_core::{UUID4, UnixNanos};
use nautilus_model::identifiers::{ClientId, TraderId, Venue};
use ustr::Ustr;
#[cfg(any(feature = "live", test))]
const ENDPOINT_MAX_LEN: usize = 128;
#[cfg(any(feature = "live", test))]
pub(crate) fn socket_endpoint(endpoint: &str) -> anyhow::Result<Ustr> {
if endpoint.is_empty() {
anyhow::bail!("Socket endpoint cannot be empty");
}
if endpoint.len() > ENDPOINT_MAX_LEN {
anyhow::bail!("Socket endpoint cannot exceed {ENDPOINT_MAX_LEN} bytes");
}
if !endpoint
.bytes()
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_'))
{
anyhow::bail!("Socket endpoint must contain only ASCII letters, digits, '.', '-', or '_'");
}
Ok(Ustr::from(endpoint))
}
/// Command requesting reconnect of one socket endpoint owned by one client.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "python",
pyo3::pyclass(module = "nautilus_trader.common", from_py_object)View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
let ep = socket_endpoint("tcp://very-long-host-name.example.internal.trading.lan:7323")?;
// after
let ep = socket_endpoint("very-long-host-name")?; // short identifier, <=128 bytes Defensive patterns
Strategy: validation
Validate before calling
const ENDPOINT_MAX_LEN: usize = 128;
fn endpoint_len_ok(s: &str) -> bool { s.len() <= ENDPOINT_MAX_LEN } Type guard
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'_')) } Try / catch
let ep = socket_endpoint(endpoint)
.map_err(|e| anyhow::anyhow!("endpoint '{endpoint}' rejected: {e}"))?; Prevention
- Pass short endpoint identifiers, never full URLs or connection strings.
- Cap generated names (hash/truncate composed segments) before validation.
- Validate length in config loaders.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Socket endpoint cannot be empty
- Socket endpoint must contain only ASCII letters, digits, '.'
- Socket suffix cannot be empty: suffix is required for messag
- rate limiter decision lock poisoned
- {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/1bc95930e2000e3e.
Report an issue: GitHub.