{"record":{"id":"4414013f50a8b32a","repo":"tailscale/tailscale","slug":"foreground-listener-already-exists-for-port-d","errorCode":null,"errorMessage":"foreground listener already exists for port %d","messagePattern":"foreground listener already exists for port (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ipn/ipnlocal/serve.go","lineNumber":1775,"sourceCode":"\t\treturn nil\n\t}\n\n\t// New foreground listeners must be on open ports.\n\tfor sessionID, incomingFg := range incoming.Foreground().All() {\n\t\tif !existing.Foreground().Has(sessionID) {\n\t\t\t// This is a new session.\n\t\t\tfor port := range incomingFg.TCPs() {\n\t\t\t\tif _, exists := existing.FindTCP(port); exists {\n\t\t\t\t\treturn fmt.Errorf(\"listener already exists for port %d\", port)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// New background listeners cannot overwrite existing foreground listeners.\n\tfor port := range incoming.TCP().All() {\n\t\tif _, exists := existing.FindForegroundTCP(port); exists {\n\t\t\treturn fmt.Errorf(\"foreground listener already exists for port %d\", port)\n\t\t}\n\t}\n\n\t// Incoming configuration cannot change the serve type in use by a port.\n\tfor port, incomingHandler := range incoming.TCP().All() {\n\t\texistingHandler, exists := existing.FindTCP(port)\n\t\tif !exists {\n\t\t\tcontinue\n\t\t}\n\n\t\texistingServeType := serveTypeFromPortHandler(existingHandler)\n\t\tincomingServeType := serveTypeFromPortHandler(incomingHandler)\n\t\tif incomingServeType != existingServeType {\n\t\t\treturn fmt.Errorf(\"want to serve %q, but port %d is already serving %q\", incomingServeType, port, existingServeType)\n\t\t}\n\t}\n\n\t// Validations for Tailscale Services.","sourceCodeStart":1757,"sourceCodeEnd":1793,"githubUrl":"https://github.com/tailscale/tailscale/blob/6e0912f97994f927632b34ae9e63b53d6516a6ac/ipn/ipnlocal/serve.go#L1757-L1793","documentation":"Raised by validateServeConfigUpdate when a background serve config wants a TCP port currently held by a foreground session. Background config cannot overwrite an active foreground listener.","triggerScenarios":"Thrown at ipn/ipnlocal/serve.go:1775 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["A foreground serve listener already exists for this port; stop the running 'tailscale serve'/'tailscale funnel' foreground process (Ctrl-C) before starting another on the same port."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6e0912f97994f927632b34ae9e63b53d6516a6ac","analyzedAt":"2026-08-18T08:17:25.280Z","contentChangedAt":"2026-08-18T08:17:25.280Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}