node-wot icon indicating copy to clipboard operation
node-wot copied to clipboard

events without subprotocol might be causing unexpected behaviour

Open VigneshVSV opened this issue 9 months ago • 3 comments

I use events primarily with HTTP SSE.

When I generate the TD without the subprotocol option within the event affordance, the node-wot client subscribes to the event multiple times.

The event afffordance (faulty) schema is as follows:


intensity_measurement_event": {
      "forms": [
        {
          "href": "https://LAPTOP-F60CU35D:8083/spectrometer/ocean-optics/USB2000-plus/intensity/measurement-event",
          "op": "subscribeevent",
          "htv:methodName": "GET",
          "contentType": "text/event-stream"
        }
      ]
    }

The validator does not complain. When the client tries to subscribe to the event:

 spectrometer.subscribeEvent("intensity_measurement_event", async(data : InteractionOutput) => {
 const value = await data.value()
 console.log("event", value, data)            
 }).then((subscription : any) => {
     intensityMeasurementEvent = subscription 
     console.debug("subscribed to intensity measurement event")
 })

This somehow leads to 6 event subscriptions to the server side. I get the following output:


App.svelte:37 consumed thing description from spectrometer
App.svelte:43 updating state
App.svelte:59 action with value InteractionOutput {form: {…}, schema: undefined, dataUsed: false}
App.svelte:60 action with value undefined
MainView.svelte:45 subscribed to intensity measurement event
MainView.svelte:42 event undefined InteractionOutput {form: {…}, schema: undefined, dataUsed: false}
MainView.svelte:42 event undefined InteractionOutput {form: {…}, schema: undefined, dataUsed: false}
MainView.svelte:42 event undefined InteractionOutput {form: {…}, schema: undefined, dataUsed: false}
MainView.svelte:42 event undefined InteractionOutput {form: {…}, schema: undefined, dataUsed: false}
MainView.svelte:42 event undefined InteractionOutput {form: {…}, schema: undefined, dataUsed: false}
App.svelte:77 rescheduling property polling function

From server side:


count 42
DEBUG    - 2024-05-02T20:29:03:171 - spectrometer/ocean-optics/USB2000-plus - starting measurement count 43
DEBUG    - 2024-05-02T20:29:03:172 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:173 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:174 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:175 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:175 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:176 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:182 - spectrometer/ocean-optics/USB2000-plus - measurement taken at 02.05.2024 20:29:04.182 - measurement count 43
DEBUG    - 2024-05-02T20:29:04:184 - spectrometer/ocean-optics/USB2000-plus - starting measurement count 44
DEBUG    - 2024-05-02T20:29:04:185 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:186 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:187 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:188 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:188 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:189 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:05:196 - spectrometer/ocean-optics/USB2000-plus - measurement taken at 02.05.2024 20:29:05.196 - measurement count 44

The event is being sent, but there are 6 of them (each line claiming "new data sent" is a single event of same type). Also, I am not able to invoke further actions.

When adding the subprotocol field, the issue is solved. However, due to absence of schema the event value is undefined. (https://github.com/eclipse-thingweb/node-wot/issues/1280)

The TD document also says subprotocol is optional, may I know what is the default value?

VigneshVSV avatar May 02 '24 17:05 VigneshVSV

By default, http-binding assumes any "event-like" affordance to be implemented with a long polling protocol. I bet that's the reason why you were seeing such weird behavior with multiple subscriptions ( the client continuously creates a GET request against the endpoint). To be honest I'm not sure how to properly solve this behaviour. What about adding a warning message? Something like: No subprotocol found defaulting to longpoll.

relu91 avatar May 09 '24 13:05 relu91

Yes sure.

Personally I would say that if there is more than one form of subprotocol possible with the same http method and URL, then subprotocol field can be made mandatory.

But of course, the warning would solve the issue of "unexpectedness"/unknown behaviour which makes the user dig deep into docs.

VigneshVSV avatar May 09 '24 13:05 VigneshVSV

I changed my mind. I think its fine if you just add a warning.

VigneshVSV avatar May 09 '24 15:05 VigneshVSV