{"record":{"id":"9e41da5e4fc9171d","repo":"pinpoint-apm/pinpoint","slug":"duplicate-service-name","errorCode":null,"errorMessage":"Duplicate service name: ","messagePattern":"Duplicate service name: ","errorType":"exception","errorClass":"DataIntegrityViolationException","httpStatus":null,"severity":"error","filePath":"service-module/src/main/java/com/navercorp/pinpoint/service/service/ServiceRegistryServiceImpl.java","lineNumber":45,"sourceCode":"        this.serviceRegistryDao = Objects.requireNonNull(serviceRegistryDao, \"serviceRegistryDao\");\n        this.serviceUidGenerator = Objects.requireNonNull(serviceUidGenerator, \"serviceUidGenerator\");\n    }\n\n    @Override\n    @Transactional(rollbackFor = {Exception.class})\n    @Retryable(retryFor = DuplicateKeyException.class, maxAttempts = 3)\n    public Service insertService(String name) {\n        StringPrecondition.requireHasLength(name, \"name\");\n        if (Service.wellKnownService(name) != null) {\n            throw new IllegalArgumentException(\"name is well known\");\n        }\n\n        int uid = serviceUidGenerator.generate().getUid();\n        try {\n            serviceRegistryDao.insertService(uid, name);\n        } catch (DuplicateKeyException e) {\n            if (serviceRegistryDao.selectServiceByName(name) != null) {\n                throw new DataIntegrityViolationException(\"Duplicate service name: \" + name, e);\n            }\n            throw e;\n        }\n\n        return new Service(name, uid);\n    }\n\n    @Override\n    @Transactional(readOnly = true)\n    public List<String> getServiceNames() {\n        return serviceRegistryDao.selectServiceNames();\n    }\n\n    @Override\n    @Transactional(readOnly = true)\n    public List<Service> getServiceList(int limit) {\n        List<ServiceEntity> entityList = serviceRegistryDao.selectServiceList(limit);\n        return toServices(entityList);","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/service-module/src/main/java/com/navercorp/pinpoint/service/service/ServiceRegistryServiceImpl.java#L27-L63","documentation":"After a DuplicateKeyException from the DAO insert, the code re-checks selectServiceByName; if a row with that name already exists, it rethrows as DataIntegrityViolationException(\"Duplicate service name: ...\"). This distinguishes a genuine name conflict from a duplicate-key caused by something else (e.g. UID collision). The method is @Retryable on DuplicateKeyException, so this explicit rethrow also stops pointless retries.","triggerScenarios":"Calling insertService with a name that already exists in the service_registry table (unique-name constraint violation on insert).","commonSituations":"Two concurrent registrations of the same name; re-running a provisioning script that already created the service; retry after a previous partial failure.","solutions":["Check existence first with selectServiceByName and reuse/update the existing service instead of inserting.","Catch DataIntegrityViolationException (or DuplicateKeyException) around insertService and handle the conflict idempotently.","Use a unique name or adopt a create-or-get pattern."],"exampleFix":"// before\nserviceRegistryService.insertService(name);\n// after\nif (serviceRegistryService.selectServiceByName(name) == null) {\n    serviceRegistryService.insertService(name);\n}","handlingStrategy":"try-catch","validationCode":"if (serviceRegistryService.selectServiceByName(name) != null) { /* already exists — skip or reuse */ }","typeGuard":null,"tryCatchPattern":"try { serviceRegistryService.insertService(name); } catch (DataIntegrityViolationException | DuplicateKeyException e) { /* handle existing-name conflict idempotently */ }","preventionTips":["Check selectServiceByName before insert","Make provisioning scripts idempotent","Avoid concurrent duplicate registrations"],"tags":["service-registry","duplicate-key","data-integrity"],"backgroundTag":"database-write-failed","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}