{"record":{"id":"8596b42eeb4695ef","repo":"apache/pulsar","slug":"s-s-doesn-t-have-instance-with-id-s","errorCode":null,"errorMessage":"%s %s doesn't have instance with id %s","messagePattern":"(.+?) (.+?) doesn't have instance with id (.+?)","errorType":"http","errorClass":"RestException","httpStatus":400,"severity":"warning","filePath":"pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java","lineNumber":1005,"sourceCode":"        }\n        FunctionMetaData functionMetaData =\n                functionMetaDataManager.getFunctionMetaData(tenant, namespace, componentName);\n        if (!InstanceUtils.calculateSubjectType(functionMetaData.getFunctionDetails()).equals(componentType)) {\n            log.error().attr(\"tenant\", tenant).attr(\"namespace\", namespace).attr(\"componentName\", componentName)\n\n                    .attr(\"componentType\", ComponentTypeUtils.toString(componentType)).log(\"/ / is not a\");\n            throw new RestException(Status.NOT_FOUND,\n                    String.format(\"%s %s doesn't exist\", ComponentTypeUtils.toString(componentType), componentName));\n\n        }\n        int instanceIdInt = Integer.parseInt(instanceId);\n        if (instanceIdInt < 0 || instanceIdInt >= functionMetaData.getFunctionDetails().getParallelism()) {\n            log.error().attr(\"componentType\", ComponentTypeUtils.toString(componentType)).attr(\"tenant\", tenant)\n\n                    .attr(\"namespace\", namespace).attr(\"componentName\", componentName)\n\n                    .log(\"instanceId in get Stats out of bounds @ / / /\");\n            throw new RestException(Status.BAD_REQUEST,\n                    String.format(\"%s %s doesn't have instance with id %s\", ComponentTypeUtils.toString(componentType),\n                            componentName, instanceId));\n        }\n\n        FunctionRuntimeManager functionRuntimeManager = worker().getFunctionRuntimeManager();\n        FunctionInstanceStatsDataImpl functionInstanceStatsData;\n        try {\n            functionInstanceStatsData =\n                    functionRuntimeManager.getFunctionInstanceStats(tenant, namespace, componentName,\n                            Integer.parseInt(instanceId), uri);\n        } catch (WebApplicationException we) {\n            throw we;\n        } catch (Exception e) {\n            log.error().attr(\"tenant\", tenant).attr(\"namespace\", namespace).attr(\"componentName\", componentName)\n\n                    .exception(e).log(\"/ / Got Exception Getting Stats\");\n            throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());\n        }","sourceCodeStart":987,"sourceCodeEnd":1023,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java#L987-L1023","documentation":"The parsed instanceId is out of range: it is negative or >= the function's configured parallelism, so getFunctionsInstanceStats throws HTTP 400 '%s %s doesn't have instance with id %s'. The function is valid but simply has no such instance.","triggerScenarios":"GET .../{tenant}/{namespace}/{name}/{instanceId}/stats with instanceId >= parallelism (e.g. asking for instance 3 of a parallelism-1 function) or a negative/non-numeric id; also after parallelism was lowered while clients cache old instance counts.","commonSituations":"Dashboards that discover instance count once and keep polling after an update reduced parallelism; off-by-one loops (<= instead of <); deleting instances after update.","solutions":["Fetch current parallelism via GET .../functions/{tenant}/{namespace}/{name} and only request instance ids in [0, parallelism)","If parallelism changed recently, refresh the instance list in clients/dashboards","Fix integer parsing so ids are non-numeric values are rejected client-side"],"exampleFix":"// before\ncurl 'http://worker:8080/admin/v3/functions/tenant/ns/fn/5/stats'  // 400, parallelism=2\n// after\n# enumerate instances 0..parallelism-1\nfor i in 0 1; do curl \"http://worker:8080/admin/v3/functions/tenant/ns/fn/$i/stats\"; done","handlingStrategy":"validation","validationCode":"// Java: bound-check instanceId against current parallelism\nFunctionConfig cfg = admin.functions().getFunction(tenant, namespace, fn);\nint parallelism = cfg.getParallelism();\nif (instanceId < 0 || instanceId >= parallelism) {\n    throw new IllegalArgumentException(\n        \"instanceId \" + instanceId + \" out of range [0,\" + parallelism + \")\");\n}","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n    FunctionInstanceStatsData s = admin.functions().getFunctionInstanceStats(tenant, namespace, fn, id);\n} catch (PulsarAdminException e) {\n    if (e.getStatusCode() == 400) { /* refresh parallelism and re-derive valid instance ids */ }\n}","preventionTips":["Fetch parallelism from the function config, never cache instance counts","Enumerate instances as 0..parallelism-1 (exclusive upper bound)","Refresh instance lists after any update that changes parallelism"],"tags":["rest-api","bad-request","instance-id","pulsar-functions"],"backgroundTag":"instance-id-out-of-range","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}