context.Orion-LD icon indicating copy to clipboard operation
context.Orion-LD copied to clipboard

Successful 201 response on registration creation, but entity not persisted

Open Mirkesx opened this issue 1 month ago • 0 comments

Hi!

Description of the issue and context

I've been working with an IoTAgent (the one with the AAS integration) running Orion-LD and I've experienced a weird bug happening when creating registrations in a very short time period.

Basically, in my use-case I have around 14 devices. When they are created, the software triggers 14 individual "Create Registration" requests to the Orion-LD at the same time. From the logs I can see that Orion-LD returns 201 for all of them, yet, when I try to list all of them with GET /ngsi-ld/v1/csourceRegistrations I only get a couple of them (usually just one) instead of 14.

Not only this, it seems that it also influences every subsequent valid Create Registration request: it always returns 201 Created (as I said they are valid requests), but it won't list the newly created registration.

Keep in mind that this is not related to the iotagent, but to Orion-LD. I was able to reproduce it using the script that you can find in the next chapter.

JS script to reproduce it

Prerequisites:

  • Lot of requests (10 to 20 ish) in a very short time (instantaneously)

I've noticed that it can happen with a lower number of requests in a short period of time, it is obviously clearer when you increase the number (that's why I suggest creating at least 10 registrations to see it).

This is the script I used to perform my tests:

send_entities_and_registrations.js

The scritps does simple things:

  • It sends 10 Create Registrations to Orion-LD without waiting for response
  • It gathers all the results and store them into a file called "results_[timestamp].json". For each operation it stores:
    • The original request (headers + body)
    • The response (headers + body)

Walkthrough of the troubleshooting process

NOTE: It doesn't seem that the presence of the "id" field in the body is part of this issue, as I tried with and without and I was able to reproduce it in both cases. In the walkthrough I will illustrate a case when the "id" is not present.

Just as an example I will illustrate one of my tests. Using the script, and setting the "COUNT" variable to 10, I get the following output:

results_2025-11-06T16-55-42-178Z.json

All 10 registrations are successful (201), and I also get an ID with it (Location header).

If I try to list all of them though, I only get these two:

GET /ngsi-ld/v1/csourceRegistrations

200 OK
[
    {
        "type": "ContextSourceRegistration",
        "id": "urn:ngsi-ld:ContextSourceRegistration:6df8cdb0-bb31-11f0-8be3-12ee6c93c54b",
        "endpoint": "http://test.com/",
        "information": [
            {
                "entities": [
                    {
                        "id": "urn:ngsi-ld:Entity:8",
                        "type": "Device"
                    }
                ]
            }
        ],
        "status": "active"
    },
    {
        "type": "ContextSourceRegistration",
        "id": "urn:ngsi-ld:ContextSourceRegistration:6df87e64-bb31-11f0-9a83-12ee6c93c54b",
        "endpoint": "http://test.com/",
        "information": [
            {
                "entities": [
                    {
                        "id": "urn:ngsi-ld:Entity:5",
                        "type": "Device"
                    }
                ]
            }
        ],
        "status": "active"
    }
]

So, I try to get one of the missing ones by Id. I try with the one associated with the entity "urn:ngsi-ld:Entity:1" which has the following id:

urn:ngsi-ld:ContextSourceRegistration:6df874be-bb31-11f0-b2fa-12ee6c93c54b

GET /ngsi-ld/v1/csourceRegistrations/urn:ngsi-ld:ContextSourceRegistration:6df874be-bb31-11f0-b2fa-12ee6c93c54b

404 NOT FOUND
{
    "type": "https://uri.etsi.org/ngsi-ld/errors/ResourceNotFound",
    "title": "Registration not found",
    "detail": "urn:ngsi-ld:ContextSourceRegistration:6df874be-bb31-11f0-b2fa-12ee6c93c54b"
}

Then I try to create a new one with the following curl request:

curl --location 'http://localhost:1026/ngsi-ld/v1/csourceRegistrations' \
--header 'Content-Type: application/json' \
--data '{
    "type": "ContextSourceRegistration",
    "endpoint": "http://test.com/",
    "information": [
        {
            "entities": [
                {
                    "id": "urn:ngsi-ld:Entity:11",
                    "type": "Device"
                }
            ]
        }
    ]
}'

It returns 201 Created with the following id in my case:

/ngsi-ld/v1/csourceRegistrations/urn:ngsi-ld:ContextSourceRegistration:16557fa8-bb32-11f0-b912-12ee6c93c54b

I try to get this one as well:

GET /ngsi-ld/v1/csourceRegistrations/urn:ngsi-ld:ContextSourceRegistration:16557fa8-bb32-11f0-b912-12ee6c93c54b

404 NOT FOUND
{
    "type": "https://uri.etsi.org/ngsi-ld/errors/ResourceNotFound",
    "title": "Registration not found",
    "detail": "urn:ngsi-ld:ContextSourceRegistration:16557fa8-bb32-11f0-b912-12ee6c93c54b"
}

Final Note

As said, this may happen or not, it usually happens with at least 10 or more Create Registrations. It can happen with less, but it was very rare in my tests.

Mirkesx avatar Nov 06 '25 17:11 Mirkesx