{"record":{"id":"af75dbfd293666f5","repo":"floci-io/floci","slug":"no-free-ports-in-range-baseport-maxpor","errorCode":null,"errorMessage":"No free ports in range \" + basePort + \"-\" + maxPort","messagePattern":"No free ports in range \" \\+ basePort \\+ \"-\" \\+ maxPort","errorType":"panic","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/core/common/port/PortAllocator.java","lineNumber":39,"sourceCode":"\n    @Inject\n    public PortAllocator(EmulatorConfig config) {\n        this(config.services().lambda().runtimeApiBasePort(),\n                config.services().lambda().runtimeApiMaxPort());\n    }\n\n    PortAllocator(int basePort, int maxPort) {\n        this.basePort = basePort;\n        this.maxPort = maxPort;\n    }\n\n    public int allocate() {\n        for (int p = basePort; p <= maxPort; p++) {\n            if (inUse.add(p)) {\n                return p;\n            }\n        }\n        throw new IllegalStateException(\n                \"No free ports in range \" + basePort + \"-\" + maxPort);\n    }\n\n    public void release(int port) {\n        inUse.remove(port);\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":47,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/core/common/port/PortAllocator.java#L21-L47","documentation":"Thrown by core/common/port/PortAllocator.allocate (the package-private, in-use-set based allocator, distinct from the docker PortAllocator) when every port in [basePort, maxPort] is already in the inUse set. This allocator does not probe the OS — it only tracks ports it handed out, and ports are returned via release(port).","triggerScenarios":"Allocating more ports than the configured basePort..maxPort span without releasing them; leaking allocations (never calling release) across many cycles; a too-narrow range for the number of simultaneous emulated listeners (e.g. RDS/ElastiCache TCP proxies).","commonSituations":"Creating and destroying many TCP-proxied resources in one emulator session where release is skipped on failure paths; a narrow default range combined with test parallelism; restart reserving many ports up front.","solutions":["Increase the configured port range for the affected subsystem","Ensure resources are deleted/closed so their ports are released before allocating more","Restart floci to reset the in-use set if allocations leaked","Reduce the number of concurrently open emulated TCP resources"],"exampleFix":"# before\nfloci.rds.port-range: 45000-45010\n\n# after\nfloci.rds.port-range: 45000-45200","handlingStrategy":"validation","validationCode":"boolean canAllocate(PortAllocator allocator, int count, int span) {\n    return allocator.availableCount() + count <= span; // or track release() calls yourself\n}","typeGuard":null,"tryCatchPattern":"try {\n    int port = allocator.allocate();\n} catch (IllegalStateException e) {\n    // in-use set full: release unused ports (delete resources) or widen range; restart resets set\n}","preventionTips":["Always release ports when the owning resource is deleted","Use try-finally around allocated ports in tests","Keep range span comfortably above peak concurrent TCP resources"],"tags":["ports","resource-exhaustion","tcp-proxy","config"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}