{"record":{"id":"8c00ee2810e53a20","repo":"ruvnet/RuView","slug":"port-must-be-between-1-and-65535","errorCode":null,"errorMessage":"Port must be between 1 and 65535","messagePattern":"Port must be between 1 and 65535","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archive/v1/src/config/settings.py","lineNumber":215,"sourceCode":"        \"\"\"Validate confidence threshold.\"\"\"\n        if not 0.0 <= v <= 1.0:\n            raise ValueError(\"Confidence threshold must be between 0.0 and 1.0\")\n        return v\n    \n    @field_validator(\"stream_fps\")\n    @classmethod\n    def validate_stream_fps(cls, v):\n        \"\"\"Validate streaming FPS.\"\"\"\n        if not 1 <= v <= 60:\n            raise ValueError(\"Stream FPS must be between 1 and 60\")\n        return v\n    \n    @field_validator(\"port\")\n    @classmethod\n    def validate_port(cls, v):\n        \"\"\"Validate port number.\"\"\"\n        if not 1 <= v <= 65535:\n            raise ValueError(\"Port must be between 1 and 65535\")\n        return v\n    \n    @field_validator(\"workers\")\n    @classmethod\n    def validate_workers(cls, v):\n        \"\"\"Validate worker count.\"\"\"\n        if v < 1:\n            raise ValueError(\"Workers must be at least 1\")\n        return v\n    \n    @field_validator(\"db_port\")\n    @classmethod\n    def validate_db_port(cls, v):\n        \"\"\"Validate database port.\"\"\"\n        if not 1 <= v <= 65535:\n            raise ValueError(\"Database port must be between 1 and 65535\")\n        return v\n    ","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/config/settings.py#L197-L233","documentation":"Pydantic v2 @field_validator on Settings.port in archive/v1/src/config/settings.py. It enforces 1 <= port <= 65535 (the valid TCP/UDP port range). An invalid PORT env value raises ValueError at Settings() construction and prevents application startup. Note this is the API port; the database port has its own separate validator.","triggerScenarios":"PORT=0 (attempting an ephemeral/dynamic port assignment); PORT=80080 or 99999 (digit-doubling typos); PORT=65536 (classic off-by-one at the range edge); negative values.","commonSituations":"Docker/K8s configs that use host port 0 for auto-assignment being copied into the app's own PORT; typos in .env files; port-scanner or proxy configs using out-of-range placeholder values; copying an internal service mesh port like 90000 from documentation.","solutions":["Set PORT to a value in 1-65535 (unprivileged apps commonly use 8000 or 8080)","If you wanted an ephemeral port (0), let the OS assign it at bind time instead of via this setting","Double the digits check: grep the .env/compose file for 5-digit ports above 65535","Prefer 1024-65535 unless the process deliberately runs as root for privileged ports"],"exampleFix":"# before\nPORT=80080\n\n# after\nPORT=8080","handlingStrategy":"validation","validationCode":"raw = int(os.environ.get(\"PORT\", \"8000\"))\nassert 1 <= raw <= 65535, f\"PORT must be 1-65535, got {raw} (5-digit values above 65535 are usually typos)\"","typeGuard":"def is_valid_port(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 65535","tryCatchPattern":"from pydantic import ValidationError\ntry:\n    settings = Settings()\nexcept ValidationError as e:\n    if any(err[\"loc\"][-1] == \"port\" for err in e.errors()):\n        raise SystemExit(\"PORT must be in 1-65535; port 0 (ephemeral) is not supported via settings\") from e\n    raise","preventionTips":["Never set PORT=0 hoping for an ephemeral assignment; let the OS assign at bind time","Lint env/compose files for ports above 65535 (digit-doubling typos)","Prefer unprivileged ports (1024+) unless the process intentionally runs privileged"],"tags":["pydantic","settings","validation","port","network","environment-variables","python"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}