{"record":{"id":"04f00af59bd67add","repo":"Mintplex-Labs/anything-llm","slug":"invalid-collector-port-process-env-collector-po-04f00a","errorCode":null,"errorMessage":"Invalid COLLECTOR_PORT \"${process.env.COLLECTOR_PORT}\". Falling back to ${this.DEFAULT_COLLECTOR_PORT}.","messagePattern":"Invalid COLLECTOR_PORT \"(.+?)\"\\. Falling back to (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/utils/collectorApi/index.js","lineNumber":45,"sourceCode":"  extensionRequestAgent = new Agent({\n    headersTimeout: this.extensionRequestTimeout,\n    bodyTimeout: this.extensionRequestTimeout,\n  });\n\n  /**\n   * Gets the collector port from the environment variables.\n   * If the port is not set, it will fall back to the default port.\n   * If the port is invalid, it will log a warning and return the default port.\n   * @returns {number}\n   */\n  static getCollectorPort() {\n    if (!(\"COLLECTOR_PORT\" in process.env)) return this.DEFAULT_COLLECTOR_PORT;\n    const port = Number(\n      process.env.COLLECTOR_PORT || this.DEFAULT_COLLECTOR_PORT\n    );\n    if (Number.isInteger(port) && port > 0 && port <= 65535) return port;\n\n    console.warn(\n      `Invalid COLLECTOR_PORT \"${process.env.COLLECTOR_PORT}\". Falling back to ${this.DEFAULT_COLLECTOR_PORT}.`\n    );\n    return this.DEFAULT_COLLECTOR_PORT;\n  }\n\n  constructor() {\n    const { CommunicationKey } = require(\"../comKey\");\n    this.comkey = new CommunicationKey();\n    this.endpoint = `http://0.0.0.0:${CollectorApi.getCollectorPort()}`;\n  }\n\n  log(text, ...args) {\n    console.log(`\\x1b[36m[CollectorApi]\\x1b[0m ${text}`, ...args);\n  }\n\n  /**\n   * Attach options to the request passed to the collector API\n   * @returns {CollectorOptions}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/collectorApi/index.js#L27-L63","documentation":"CollectorApi.getCollectorPort() builds the base URL for every collector call (http://0.0.0.0:<port>). If COLLECTOR_PORT is set, it is coerced with Number() and must be an integer in 1–65535; anything else (NaN, fractional, zero, negative, >65535) triggers this warning and the default port is used instead. An unset or empty variable silently uses the default with no warning. The danger is indirect: with the wrong port, subsequent calls fail and you later see \"Collector API is not online\" in chats.","triggerScenarios":"COLLECTOR_PORT=\"abc\" (Number → NaN), \"8888.5\" (not an integer), \"0\", \"-1\", \"70000\"/\"99999\" (out of range), or values with quotes/whitespace inherited from .env, docker-compose.yml, or Kubernetes env definitions.","commonSituations":"Quoting numeric env values (COLLECTOR_PORT='8888') in compose files, typos like COLLECTOR_PORT=88 88, pasting a protocol or service name (http://collector, collector:8888) into a port field, or changing the collector's listen port without updating the server side. The mismatch then breaks document parsing with a misleading \"not online\" symptom.","solutions":["Set COLLECTOR_PORT to a bare integer between 1 and 65535 that matches the collector's actual listen port (e.g. COLLECTOR_PORT=8888), with no quotes, spaces, or protocol prefix.","Verify both sides agree: the collector's own PORT/BIND settings and the server's COLLECTOR_PORT, plus any docker port mapping host:container.","Remove the variable entirely if you want the documented default port.","Restart the server after fixing — the endpoint string is built once in the CollectorApi constructor."],"exampleFix":"# before (docker-compose.yml)\nenvironment:\n  - COLLECTOR_PORT='8888'\n\n# after\nenvironment:\n  - COLLECTOR_PORT=8888","handlingStrategy":"validation","validationCode":"const rawPort = process.env.COLLECTOR_PORT;\nif (rawPort !== undefined && rawPort !== \"\" && !isValidPort(rawPort)) {\n  throw new Error(`COLLECTOR_PORT \"${rawPort}\" is invalid — use an integer between 1 and 65535.`);\n}","typeGuard":"const isValidPort = (v) => {\n  const n = Number(v);\n  return Number.isInteger(n) && n > 0 && n <= 65535;\n};","tryCatchPattern":null,"preventionTips":["Never quote or annotate numeric env values; a compose linter (docker compose config) will render and expose such mistakes before deploy.","When changing the collector's listen port, update it as a single variable shared by both services rather than duplicating literals.","Assert required env shape in a preboot check so a bad port fails loudly at startup instead of degrading into 'Collector API is not online'."],"tags":["env-var","port","configuration","collector","docker"],"backgroundTag":"invalid-port-configuration","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}