FIWARE / context.Orion-LD

Context Broker and CEF building block for context data management which supports both the NGSI-LD and the NGSI-v2 APIs
https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.06.01_60/gs_CIM009v010601p.pdf
GNU Affero General Public License v3.0
50 stars 42 forks source link

Exception using subscriptions in a mixed environment (LD and V2) #1649

Open tudamp opened 1 month ago

tudamp commented 1 month ago

Environment

orion-ld:1.6.0 mongo:3.6

Description

We are using orion-ld in an environment where there are components using the V2 part and others using the LD part.

Recently we realised that when we have both ‘V2-type’ and ‘LD-type’ subscriptions in the same NGSI-Tenant, the call to /v2/subscriptions throws an exception that crashes orion-ld. The error output is: terminate called after throwing an instance of ‘mongo::MsgAssertionException’ what(): wrong type for field (_id) 2 != 7

In the same NGSI-Tenant, the call to the LD endpoint is executed correctly. If no LD subscriptions are present the V2 endpoint responds correctly.

kzangeli commented 1 week ago

ok, that definitely sounds like a stupid bug I need to fix. Could you please provide the exact payload bodies for the two subscriptions. Having that it should be straightforward to reproduce the issue and then also straightforward to fix it. Thank you for reporting!

tudamp commented 1 week ago

Thank you for your attention!

I realised that it is sufficient to have a registered subscription and then query V2 API

curl -X POST -H 'fiware-service: test' -H 'fiware-servicepath: /#' -H 'content-type: application/ld+json' -d '{
  "description": "Notify me of all product price changes",
  "type": "Subscription",
  "entities": [{"type": "Product"}],
  "watchedAttributes": ["price"],
  "notification": {
    "format": "keyValues",
    "endpoint": {
      "uri": "http://tutorial:3000/subscription/price-change",
      "accept": "application/json"
    }
  },
   "@context": "https://smartdatamodels.org/context.jsonld"
}' http://localhost:1026/ngsi-ld/v1/subscriptions`

and then:

curl -H 'fiware-service: test' http://localhost:1026/v2/subscriptions
curl: (52) Empty reply from server

I hope this helps

kzangeli commented 1 week ago

That should really help. Thanks!

kzangeli commented 1 week ago

So, I implemented a functional test for this. Only, it doesn't fail. All good ...

I used mongo v3.6 and what I have in the develop branch right now. No error. I also tried the version 1.6.0 of Orion-LD. Also no problem. So, not able to reproduce. Need more input. Please supply the dockerfile you use for Orion-LD and I'll start my Orion-LD with the exact same parameters. In my test I used only:

-multiservice [-experimental]

(I tried both with and without the -experimental CLI)

kzangeli commented 1 week ago

Forget the comment about not being able to reproduce. I did the GET /subscriptions using LD and not V2. Once I realized my mistake, I reproduced the crash immediately, and in a few minutes I fixed it. PR on its way, should be ready in an hour or so.